Advertisement
pb_jiang

ABC203D WA

Nov 19th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. // Problem: D - Pond
  2. // Contest: AtCoder - AtCoder Beginner Contest 203(Sponsored by Panasonic)
  3. // URL: https://atcoder.jp/contests/abc203/tasks/abc203_d
  4. // Memory Limit: 1024 MB
  5. // Time Limit: 2000 ms
  6. //
  7. // Powered by CP Editor (https://cpeditor.org)
  8.  
  9. #include <assert.h>
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  13. template <typename... Args> void logger(string vars, Args &&... values)
  14. {
  15.     cerr << vars << " = ";
  16.     string delim = "";
  17.     (..., (cerr << delim << values, delim = ", "));
  18.     cerr << endl;
  19. }
  20.  
  21. template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
  22. template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
  23. template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
  24. template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
  25.  
  26. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  27. using ll = long long;
  28. using pii = pair<int, int>;
  29.  
  30. int k, n;
  31.  
  32. int main(int argc, char **argv)
  33. {
  34.     cin >> n >> k;
  35.     auto v = vv<int>(n);
  36.     for (int i = 0; i < n; ++i)
  37.         for (int j = 0; j < n; ++j)
  38.             cin >> v[i][j];
  39.  
  40.     auto check = [&v](int x) {
  41.         auto ps = vv<ll>(n + 1);
  42.         for (int i = 0; i < n; ++i)
  43.             for (int j = 0; j < n; ++j)
  44.                 ps[i + 1][j + 1] = ps[i + 1][j] + ps[i][j + 1] + (v[i][j] <= x ? 1 : 0) - ps[i][j];
  45.         for (int i = k; i <= n; ++i)
  46.             for (int j = k; j <= n; ++j)
  47.                 if (ps[i][j] - ps[i - k][j] - ps[i][j - k] + ps[i - k][j - k] >= k * k / 2 + 1)
  48.                     return true;
  49.         return false;
  50.     };
  51.     int lb = 0, ub = 1e9 + 3, cnt = ub - lb, step, it;
  52.     while (cnt) {
  53.         it = lb, step = cnt / 2, it += step;
  54.         if (!check(it)) {
  55.             lb = it + 1;
  56.             cnt -= step + 1;
  57.         } else
  58.             cnt = step;
  59.     }
  60.     cerr << check(lb - 1) << endl;
  61.     cout << lb << endl;
  62.     return 0;
  63. };
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement