Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: D - Pond
- // Contest: AtCoder - AtCoder Beginner Contest 203(Sponsored by Panasonic)
- // URL: https://atcoder.jp/contests/abc203/tasks/abc203_d
- // Memory Limit: 1024 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
- template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
- template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
- template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int k, n;
- int main(int argc, char **argv)
- {
- cin >> n >> k;
- auto v = vv<int>(n);
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- cin >> v[i][j];
- auto check = [&v](int x) {
- auto ps = vv<ll>(n + 1);
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j)
- ps[i + 1][j + 1] = ps[i + 1][j] + ps[i][j + 1] + (v[i][j] <= x ? 1 : 0) - ps[i][j];
- for (int i = k; i <= n; ++i)
- for (int j = k; j <= n; ++j)
- if (ps[i][j] - ps[i - k][j] - ps[i][j - k] + ps[i - k][j - k] >= k * k / 2 + 1)
- return true;
- return false;
- };
- int lb = 0, ub = 1e9 + 3, cnt = ub - lb, step, it;
- while (cnt) {
- it = lb, step = cnt / 2, it += step;
- if (!check(it)) {
- lb = it + 1;
- cnt -= step + 1;
- } else
- cnt = step;
- }
- cerr << check(lb - 1) << endl;
- cout << lb << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement