Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Слава Україні, Героям слава
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e3 + 7;
- bool pode[N][N][4], vis[N][N];
- // 0 -> up, 1 -> down, 2 -> left, 3 -> right
- int dx[] = {0, 0, -1, 1};
- int dy[] = {1, -1, 0, 0};
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- memset(pode, true, sizeof(pode));
- int n;
- cin >> n;
- n++;
- vector<pair<int, int>> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i].first >> v[i].second;
- }
- for(int i = 0; i < n - 1; i++) {
- if(v[i].second == v[i + 1].second) {
- for(int x = min(v[i].first, v[i + 1].first) + 1; x <= max(v[i].first, v[i + 1].first); x++) {
- pode[x][v[i].second][0] = false;
- pode[x][v[i].second + 1][1] = false;
- }
- } else {
- for(int y = min(v[i].second, v[i + 1].second) + 1; y <= max(v[i].second, v[i + 1].second); y++) {
- pode[v[i].first][y][3] = false;
- pode[v[i].first + 1][y][2] = false;
- }
- }
- }
- int ans = 0;
- for(int i = 0; i <= 1000; i++) {
- for(int j = 0; j <= 1000; j++) {
- if(!vis[i][j]) {
- queue<pair<int, int>> q;
- vis[i][j] = true;
- q.push({i, j});
- int cnt = 0;
- while(!q.empty()) {
- auto p = q.front(); q.pop();
- cnt++;
- for(int k = 0; k < 4; k++) {
- int x = p.first + dx[k];
- int y = p.second + dy[k];
- if(x >= 0 and x < N and y >= 0 and y < N and !vis[x][y] and pode[p.first][p.second][k]) {
- vis[x][y] = true;
- q.push({x, y});
- }
- }
- }
- if(i) {
- ans = max(ans, cnt);
- }
- }
- }
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement