Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- bool sh = 0;
- int mx = 2e3 + 100;
- vector <vector <bool> > was(mx, vector <bool> (mx, 0));
- vector <vector <int> > dsk(mx, vector <int> (mx, 0));
- vector <int> dx = {-1, 1, 0, 0}, dy = {0, 0, 1, -1};
- bool ok(int i, int j) {
- return i >= 0 && i < mx && j >= 0 && j < mx && dsk[i][j] == 1 && !was[i][j];
- }
- int cnt = -1;
- void dfs(int i, int j) {
- cnt++;
- was[i][j] = 1;
- for (int to = 0; to < 4; ++to) {
- int x = i + dx[to], y = j + dy[to];
- if (ok(x, y)) {
- dfs(x, y);
- }
- }
- }
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- int n; cin >> n;
- for (int i = 0; i < n; ++i) {
- int x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- x1 += 1e3;
- x2 += 1e3;
- y1 += 1e3;
- y2 += 1e3;
- if (x1 > x2) {
- swap(x1, x2);
- }
- if (y1 > y2) {
- swap(y1, y2);
- }
- for (int j = x1; j < x2; ++j) {
- for (int i = y1; i < y2; ++i) {
- dsk[i][j] = 1;
- }
- }
- }
- if (sh) {
- cout << "dsk\n";
- for (int i = 1e3 - 10; i < 1e3 + 20; ++i) {
- for (int j = 1e3 - 10; j < 1e3 + 20; ++j) {
- cout << dsk[i][j] << ' ';
- } cout << "\n";
- } cout << "\n";
- //cout << "was\n";
- //cvv(was);
- }
- int ans = -1;
- for (int i = 0; i < mx; ++i) {
- for (int j = 0; j < mx; ++j) {
- if (dsk[i][j] == 1 && !was[i][j]) {
- cnt = 0;
- dfs(i, j);
- }
- ans = max(ans, cnt);
- }
- }
- if (sh) {
- cout << "ans = \n";
- }
- cout << ans;
- }
- /*
- 5
- -4 -5 -1 -1
- -2 -2 2 4
- -3 3 7 4
- 7 1 6 3
- 7 1 8 -2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement