Advertisement
cosenza987

vou chorar

Oct 9th, 2022
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. //Слава Україні, Героям слава
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. const int N = 1e3 + 7;
  8.  
  9. bool pode[N][N][4], vis[N][N];
  10.  
  11. // 0 -> up, 1 -> down, 2 -> left, 3 -> right
  12. int dx[] = {0, 0, -1, 1};
  13. int dy[] = {1, -1, 0, 0};
  14.  
  15. int main() {
  16.     ios_base::sync_with_stdio(false);
  17.     cin.tie(nullptr);
  18.     memset(pode, true, sizeof(pode));
  19.     int n;
  20.     cin >> n;
  21.     n++;
  22.     vector<pair<int, int>> v(n);
  23.     for(int i = 0; i < n; i++) {
  24.         cin >> v[i].first >> v[i].second;
  25.     }
  26.     for(int i = 0; i < n - 1; i++) {
  27.         if(v[i].second == v[i + 1].second) {
  28.             for(int x = min(v[i].first, v[i + 1].first) + 1; x <= max(v[i].first, v[i + 1].first); x++) {
  29.                 pode[x][v[i].second][0] = false;
  30.                 pode[x][v[i].second + 1][1] = false;
  31.             }
  32.         } else {
  33.             for(int y = min(v[i].second, v[i + 1].second) + 1; y <= max(v[i].second, v[i + 1].second); y++) {
  34.                 pode[v[i].first][y][3] = false;
  35.                 pode[v[i].first + 1][y][2] = false;
  36.             }
  37.         }
  38.     }
  39.     int ans = 0;
  40.     for(int i = 0; i <= 1000; i++) {
  41.         for(int j = 0; j <= 1000; j++) {
  42.             if(!vis[i][j]) {
  43.                 queue<pair<int, int>> q;
  44.                 vis[i][j] = true;
  45.                 q.push({i, j});
  46.                 int cnt = 0;
  47.                 while(!q.empty()) {
  48.                     auto p = q.front(); q.pop();
  49.                     cnt++;
  50.                     for(int k = 0; k < 4; k++) {
  51.                         int x = p.first + dx[k];
  52.                         int y = p.second + dy[k];
  53.                         if(x >= 0 and x < N and y >= 0 and y < N and !vis[x][y] and pode[p.first][p.second][k]) {
  54.                             vis[x][y] = true;
  55.                             q.push({x, y});
  56.                         }
  57.                     }
  58.                 }
  59.                 if(i) {
  60.                     ans = max(ans, cnt);
  61.                 }
  62.             }
  63.         }
  64.     }
  65.     cout << ans << "\n";
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement