Advertisement
Korotkodul

ШВБ_21-22_N3

Oct 22nd, 2022 (edited)
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool sh = 0;
  51.  
  52. int mx = 2e3 + 100;
  53.  
  54. vector <vector <bool> > was(mx, vector <bool> (mx, 0));
  55. vector <vector <int> > dsk(mx, vector <int> (mx, 0));
  56.  
  57. vector <int> dx = {-1, 1, 0, 0}, dy = {0, 0, 1, -1};
  58. bool ok(int i, int j) {
  59.     return i >= 0 && i < mx && j >= 0 && j < mx && dsk[i][j] == 1 && !was[i][j];
  60. }
  61.  
  62. int cnt = -1;
  63.  
  64. void dfs(int i, int j) {
  65.     cnt++;
  66.     was[i][j] = 1;
  67.     for (int to = 0; to < 4; ++to) {
  68.         int x = i + dx[to], y = j + dy[to];
  69.         if (ok(x, y)) {
  70.             dfs(x, y);
  71.         }
  72.     }
  73. }
  74.  
  75.  
  76. int main() {
  77.     /*ios::sync_with_stdio(0);
  78.     cin.tie(0);
  79.     cout.tie(0);*/
  80.  
  81.     int n; cin >> n;
  82.     for (int i = 0; i < n; ++i) {
  83.         int x1, y1, x2, y2;
  84.         cin >> x1 >> y1 >> x2 >> y2;
  85.         x1 += 1e3;
  86.         x2 += 1e3;
  87.         y1 += 1e3;
  88.         y2 += 1e3;
  89.         if (x1 > x2) {
  90.             swap(x1, x2);
  91.         }
  92.         if (y1 > y2) {
  93.             swap(y1, y2);
  94.         }
  95.         for (int j = x1; j < x2; ++j) {
  96.             for (int i = y1; i < y2; ++i) {
  97.                 dsk[i][j] = 1;
  98.             }
  99.         }
  100.     }
  101.     if (sh) {
  102.         cout << "dsk\n";
  103.         for (int i = 1e3 -  10; i < 1e3 + 20; ++i) {
  104.             for (int j = 1e3 - 10; j < 1e3 + 20; ++j) {
  105.                 cout << dsk[i][j] << ' ';
  106.             } cout << "\n";
  107.         } cout << "\n";
  108.         //cout << "was\n";
  109.         //cvv(was);
  110.     }
  111.     int ans = -1;
  112.     for (int i = 0; i < mx; ++i) {
  113.         for (int j = 0; j < mx; ++j) {
  114.             if (dsk[i][j] == 1 && !was[i][j]) {
  115.                 cnt = 0;
  116.                 dfs(i, j);
  117.             }
  118.             ans = max(ans, cnt);
  119.         }
  120.     }
  121.     if (sh) {
  122.         cout << "ans = \n";
  123.     }
  124.     cout << ans;
  125. }
  126. /*
  127. 5
  128. -4 -5 -1 -1
  129. -2 -2 2 4
  130. -3 3 7 4
  131. 7 1 6 3
  132. 7 1 8 -2
  133. */
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement