Advertisement
Gosunov

kompege 27 WA

Jun 17th, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn = 1010;
  5. int pref[maxn][maxn];
  6. int p[maxn][maxn];
  7.  
  8. int n;
  9.  
  10. void build() {
  11.     for (int i = 0; i < n; ++i) {
  12.         for (int j = 0; j < n; ++j) {
  13.             pref[i + 1][j + 1] = p[i][j] + pref[i][j + 1] + pref[i + 1][j] - pref[i][j];
  14.         }
  15.     }
  16. }
  17.  
  18. int get(int x1, int y1, int x2, int y2) {
  19.     return pref[x2 - 1][y2 - 1] - pref[x1][y2 - 1] - pref[x2 - 1][y1] + pref[x1][y1];
  20. }
  21.  
  22. bool check_rect(int a, int b) {
  23.     for (int i = 0; i < n; ++i) {
  24.         for (int j = 0; j < n; ++j) {
  25.             if (i + a > n || j + b > n)
  26.                 continue;
  27.             if (get(i, j, i + a, j + b) == 0)
  28.                 return true;
  29.         }
  30.     }
  31.     return false;
  32. }
  33.  
  34. bool check(int s) {
  35.     for (int i = 1; i * i <= s; ++i) {
  36.         if (s % i == 0 && check_rect(i, s / i))
  37.                 return true;
  38.     }
  39.     return false;
  40. }
  41.  
  42. void solve() {
  43.     cin >> n >> n;
  44.     int k;
  45.     cin >> k;
  46.     for (int i = 0; i < k; ++i) {
  47.         int x, y;
  48.         cin >> x >> y;
  49.         x--, y--;
  50.         p[x][y] = 1;
  51.     }
  52.     build();
  53.     cout << check(7) << '\n';
  54.     int l = 0;
  55.     int r = 1e6;
  56.     while (r - l > 1) {
  57.         int m = (r + l) / 2;
  58.         if (check(m)) {
  59.             l = m;
  60.         } else {
  61.             r = m;
  62.         }
  63.     }
  64.     cout << l << '\n';
  65. }
  66.  
  67. signed main() {
  68.     ios::sync_with_stdio(0); cin.tie(0);
  69.     solve();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement