Advertisement
MKcrazy8

Untitled

Feb 14th, 2023 (edited)
1,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4.  
  5. // Supported by https://peltorator.ru/posts/prefix_sums/
  6.  
  7. int main() {
  8.     std::cin.tie(nullptr);
  9.     std::cout.tie(nullptr);
  10.     std::ios_base::sync_with_stdio(false);
  11.     int16_t n, m;
  12.     std::cin >> n >> m;
  13.     std::vector<std::vector<int16_t>> vec;
  14.     for (int16_t i = 0; i < n; ++i) {
  15.         std::vector<int16_t> v(m);
  16.         for (int16_t j = 0; j < m; ++j) {
  17.             std::cin >> v[j];
  18.         }
  19.         vec.push_back(v);
  20.     }
  21.     std::vector<std::vector<int>> pref(n + 1, std::vector<int>(m + 1, 0));
  22.     for (int16_t i = 0; i < n; ++i) {
  23.         for (int16_t j = 0; j < m; ++j) {
  24.             pref[i + 1][j + 1] = pref[i][j + 1] + pref[i + 1][j] - pref[i][j] + vec[i][j];
  25.         }
  26.     }
  27.     vec.clear();
  28.     int mx = 1;
  29.     for (int y1 = 1; y1 < n; ++y1) {
  30.         for (int x1 = 1; x1 < m; ++x1) {
  31.             int x2 = x1 + mx;
  32.             int y2 = y1 + mx;
  33.             if (x2 < m + 1 && y2 < n + 1) {
  34.                 int sum = pref[y2][x2] + pref[y1 - 1][x1 - 1] - pref[y1 - 1][x2] - pref[y2][x1 - 1];
  35.                 if (sum == pow(x2 - x1 + 1, 2)) {
  36.                     mx = x2 - x1 + 1;
  37.                     --x1;
  38.                 }
  39.             }
  40.         }
  41.     }
  42.     pref.clear();
  43.     std::cout << mx;
  44.     return 0;
  45. }
  46.  
Tags: Etask
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement