Submission #1034122

# Submission time Handle Problem Language Result Execution time Memory
1034122 2024-07-25T09:54:20 Z AmirAli_H1 Rectangles (IOI19_rect) C++17
72 / 100
5000 ms 537940 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "rect.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2500 + 4;

int n, m;
int L1[maxn][maxn], R1[maxn][maxn];
int L2[maxn][maxn], R2[maxn][maxn];
vector<int> ls[maxn][maxn];

bool ok(int l1, int r1, int l2, int r2) {
	for (int j = l2; j <= r2; j++) {
		int i1 = l1 - 1, i2 = r1 + 1;
		if (L1[i2][j] != i1 && R1[i1][j] != i2) return 0;
	}
	for (int i = l1; i <= r1; i++) {
		int j1 = l2 - 1, j2 = r2 + 1;
		if (L2[i][j2] != j1 && R2[i][j1] != j2) return 0;
	}
	return 1;
}

ll count_rectangles(vector<vector<int>> A) {
	n = len(A); m = len(A[0]);
	
	for (int j = 0; j < m; j++) {
		for (int i = 0; i < n; i++) {
			for (L1[i][j] = i - 1; L1[i][j] != -1 && A[i][j] > A[L1[i][j]][j]; L1[i][j] = L1[L1[i][j]][j]);
		}
		for (int i = n - 1; i >= 0; i--) {
			for (R1[i][j] = i + 1; R1[i][j] != n && A[i][j] > A[R1[i][j]][j]; R1[i][j] = R1[R1[i][j]][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (L2[i][j] = j - 1; L2[i][j] != -1 && A[i][j] > A[i][L2[i][j]]; L2[i][j] = L2[i][L2[i][j]]);
		}
		for (int j = m - 1; j >= 0; j--) {
			for (R2[i][j] = j + 1; R2[i][j] != m && A[i][j] > A[i][R2[i][j]]; R2[i][j] = R2[i][R2[i][j]]);
		}
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (L1[i][j] != -1 && L1[i][j] + 1 <= i - 1) {
				ls[L1[i][j]][j].pb(i);
			}
			if (R1[i][j] != n && i + 1 <= R1[i][j] - 1 && A[i][j] != A[R1[i][j]][j]) {
				ls[i][j].pb(R1[i][j]);
			}
		}
	}
	
	ll ans = 0;
	for (int i = 1; i < n - 1; i++) {
		for (int j = 0; j < m; j++) {
			if (L2[i][j] != -1 && L2[i][j] + 1 <= j - 1) {
				for (int x : ls[i - 1][j - 1]) {
					ans += ok(i, x - 1, L2[i][j] + 1, j - 1);
				}
			}
			if (R2[i][j] != m && j + 1 <= R2[i][j] - 1 && A[i][j] != A[i][R2[i][j]]) {
				for (int x : ls[i - 1][j + 1]) {
					ans += ok(i, x - 1, j + 1, R2[i][j] - 1);
				}
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 147540 KB Output is correct
2 Correct 64 ms 148176 KB Output is correct
3 Correct 64 ms 148048 KB Output is correct
4 Correct 86 ms 148032 KB Output is correct
5 Correct 70 ms 148176 KB Output is correct
6 Correct 79 ms 147968 KB Output is correct
7 Correct 63 ms 148032 KB Output is correct
8 Correct 66 ms 147740 KB Output is correct
9 Correct 66 ms 148052 KB Output is correct
10 Correct 64 ms 148020 KB Output is correct
11 Correct 66 ms 148052 KB Output is correct
12 Correct 63 ms 148052 KB Output is correct
13 Correct 63 ms 147540 KB Output is correct
14 Correct 69 ms 147608 KB Output is correct
15 Correct 75 ms 147876 KB Output is correct
16 Correct 80 ms 147692 KB Output is correct
17 Correct 68 ms 147536 KB Output is correct
18 Correct 66 ms 147544 KB Output is correct
19 Correct 70 ms 148052 KB Output is correct
20 Correct 72 ms 148048 KB Output is correct
21 Correct 62 ms 147792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 147540 KB Output is correct
2 Correct 64 ms 148176 KB Output is correct
3 Correct 64 ms 148048 KB Output is correct
4 Correct 86 ms 148032 KB Output is correct
5 Correct 70 ms 148176 KB Output is correct
6 Correct 79 ms 147968 KB Output is correct
7 Correct 63 ms 148032 KB Output is correct
8 Correct 66 ms 147740 KB Output is correct
9 Correct 66 ms 148052 KB Output is correct
10 Correct 64 ms 148020 KB Output is correct
11 Correct 66 ms 148052 KB Output is correct
12 Correct 63 ms 148052 KB Output is correct
13 Correct 63 ms 147540 KB Output is correct
14 Correct 69 ms 147608 KB Output is correct
15 Correct 75 ms 147876 KB Output is correct
16 Correct 80 ms 147692 KB Output is correct
17 Correct 68 ms 147536 KB Output is correct
18 Correct 66 ms 147544 KB Output is correct
19 Correct 70 ms 148052 KB Output is correct
20 Correct 72 ms 148048 KB Output is correct
21 Correct 62 ms 147792 KB Output is correct
22 Correct 61 ms 149328 KB Output is correct
23 Correct 90 ms 149328 KB Output is correct
24 Correct 63 ms 149332 KB Output is correct
25 Correct 62 ms 149076 KB Output is correct
26 Correct 68 ms 149160 KB Output is correct
27 Correct 61 ms 149072 KB Output is correct
28 Correct 62 ms 149076 KB Output is correct
29 Correct 63 ms 149076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 147540 KB Output is correct
2 Correct 64 ms 148176 KB Output is correct
3 Correct 64 ms 148048 KB Output is correct
4 Correct 86 ms 148032 KB Output is correct
5 Correct 70 ms 148176 KB Output is correct
6 Correct 79 ms 147968 KB Output is correct
7 Correct 63 ms 148032 KB Output is correct
8 Correct 66 ms 147740 KB Output is correct
9 Correct 66 ms 148052 KB Output is correct
10 Correct 64 ms 148020 KB Output is correct
11 Correct 66 ms 148052 KB Output is correct
12 Correct 63 ms 148052 KB Output is correct
13 Correct 63 ms 147540 KB Output is correct
14 Correct 69 ms 147608 KB Output is correct
15 Correct 75 ms 147876 KB Output is correct
16 Correct 80 ms 147692 KB Output is correct
17 Correct 61 ms 149328 KB Output is correct
18 Correct 90 ms 149328 KB Output is correct
19 Correct 63 ms 149332 KB Output is correct
20 Correct 62 ms 149076 KB Output is correct
21 Correct 68 ms 149160 KB Output is correct
22 Correct 61 ms 149072 KB Output is correct
23 Correct 62 ms 149076 KB Output is correct
24 Correct 63 ms 149076 KB Output is correct
25 Correct 68 ms 147536 KB Output is correct
26 Correct 66 ms 147544 KB Output is correct
27 Correct 70 ms 148052 KB Output is correct
28 Correct 72 ms 148048 KB Output is correct
29 Correct 62 ms 147792 KB Output is correct
30 Correct 70 ms 153172 KB Output is correct
31 Correct 78 ms 153020 KB Output is correct
32 Correct 74 ms 153212 KB Output is correct
33 Correct 65 ms 152148 KB Output is correct
34 Correct 73 ms 152404 KB Output is correct
35 Correct 68 ms 152660 KB Output is correct
36 Correct 73 ms 152512 KB Output is correct
37 Correct 69 ms 152656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 147540 KB Output is correct
2 Correct 64 ms 148176 KB Output is correct
3 Correct 64 ms 148048 KB Output is correct
4 Correct 86 ms 148032 KB Output is correct
5 Correct 70 ms 148176 KB Output is correct
6 Correct 79 ms 147968 KB Output is correct
7 Correct 63 ms 148032 KB Output is correct
8 Correct 66 ms 147740 KB Output is correct
9 Correct 66 ms 148052 KB Output is correct
10 Correct 64 ms 148020 KB Output is correct
11 Correct 66 ms 148052 KB Output is correct
12 Correct 63 ms 148052 KB Output is correct
13 Correct 63 ms 147540 KB Output is correct
14 Correct 69 ms 147608 KB Output is correct
15 Correct 75 ms 147876 KB Output is correct
16 Correct 80 ms 147692 KB Output is correct
17 Correct 61 ms 149328 KB Output is correct
18 Correct 90 ms 149328 KB Output is correct
19 Correct 63 ms 149332 KB Output is correct
20 Correct 62 ms 149076 KB Output is correct
21 Correct 68 ms 149160 KB Output is correct
22 Correct 61 ms 149072 KB Output is correct
23 Correct 62 ms 149076 KB Output is correct
24 Correct 63 ms 149076 KB Output is correct
25 Correct 70 ms 153172 KB Output is correct
26 Correct 78 ms 153020 KB Output is correct
27 Correct 74 ms 153212 KB Output is correct
28 Correct 65 ms 152148 KB Output is correct
29 Correct 73 ms 152404 KB Output is correct
30 Correct 68 ms 152660 KB Output is correct
31 Correct 73 ms 152512 KB Output is correct
32 Correct 69 ms 152656 KB Output is correct
33 Correct 68 ms 147536 KB Output is correct
34 Correct 66 ms 147544 KB Output is correct
35 Correct 70 ms 148052 KB Output is correct
36 Correct 72 ms 148048 KB Output is correct
37 Correct 62 ms 147792 KB Output is correct
38 Correct 99 ms 181132 KB Output is correct
39 Correct 109 ms 181072 KB Output is correct
40 Correct 100 ms 175188 KB Output is correct
41 Correct 94 ms 174808 KB Output is correct
42 Correct 400 ms 188892 KB Output is correct
43 Correct 426 ms 188952 KB Output is correct
44 Correct 437 ms 189152 KB Output is correct
45 Correct 391 ms 186460 KB Output is correct
46 Correct 104 ms 174976 KB Output is correct
47 Correct 113 ms 176420 KB Output is correct
48 Correct 146 ms 179992 KB Output is correct
49 Correct 144 ms 181780 KB Output is correct
50 Correct 101 ms 170324 KB Output is correct
51 Correct 97 ms 164688 KB Output is correct
52 Correct 138 ms 180304 KB Output is correct
53 Correct 137 ms 181328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 147796 KB Output is correct
2 Correct 69 ms 147792 KB Output is correct
3 Correct 62 ms 147792 KB Output is correct
4 Correct 62 ms 147540 KB Output is correct
5 Correct 61 ms 147792 KB Output is correct
6 Correct 58 ms 147796 KB Output is correct
7 Correct 62 ms 147796 KB Output is correct
8 Correct 62 ms 147792 KB Output is correct
9 Correct 66 ms 147796 KB Output is correct
10 Correct 67 ms 147792 KB Output is correct
11 Correct 66 ms 147796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 147536 KB Output is correct
2 Correct 66 ms 147544 KB Output is correct
3 Correct 70 ms 148052 KB Output is correct
4 Correct 72 ms 148048 KB Output is correct
5 Correct 62 ms 147792 KB Output is correct
6 Correct 61 ms 147792 KB Output is correct
7 Correct 360 ms 246416 KB Output is correct
8 Correct 542 ms 354680 KB Output is correct
9 Correct 553 ms 355760 KB Output is correct
10 Correct 570 ms 355696 KB Output is correct
11 Correct 175 ms 226256 KB Output is correct
12 Correct 273 ms 303376 KB Output is correct
13 Correct 286 ms 307028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 147540 KB Output is correct
2 Correct 64 ms 148176 KB Output is correct
3 Correct 64 ms 148048 KB Output is correct
4 Correct 86 ms 148032 KB Output is correct
5 Correct 70 ms 148176 KB Output is correct
6 Correct 79 ms 147968 KB Output is correct
7 Correct 63 ms 148032 KB Output is correct
8 Correct 66 ms 147740 KB Output is correct
9 Correct 66 ms 148052 KB Output is correct
10 Correct 64 ms 148020 KB Output is correct
11 Correct 66 ms 148052 KB Output is correct
12 Correct 63 ms 148052 KB Output is correct
13 Correct 63 ms 147540 KB Output is correct
14 Correct 69 ms 147608 KB Output is correct
15 Correct 75 ms 147876 KB Output is correct
16 Correct 80 ms 147692 KB Output is correct
17 Correct 61 ms 149328 KB Output is correct
18 Correct 90 ms 149328 KB Output is correct
19 Correct 63 ms 149332 KB Output is correct
20 Correct 62 ms 149076 KB Output is correct
21 Correct 68 ms 149160 KB Output is correct
22 Correct 61 ms 149072 KB Output is correct
23 Correct 62 ms 149076 KB Output is correct
24 Correct 63 ms 149076 KB Output is correct
25 Correct 70 ms 153172 KB Output is correct
26 Correct 78 ms 153020 KB Output is correct
27 Correct 74 ms 153212 KB Output is correct
28 Correct 65 ms 152148 KB Output is correct
29 Correct 73 ms 152404 KB Output is correct
30 Correct 68 ms 152660 KB Output is correct
31 Correct 73 ms 152512 KB Output is correct
32 Correct 69 ms 152656 KB Output is correct
33 Correct 99 ms 181132 KB Output is correct
34 Correct 109 ms 181072 KB Output is correct
35 Correct 100 ms 175188 KB Output is correct
36 Correct 94 ms 174808 KB Output is correct
37 Correct 400 ms 188892 KB Output is correct
38 Correct 426 ms 188952 KB Output is correct
39 Correct 437 ms 189152 KB Output is correct
40 Correct 391 ms 186460 KB Output is correct
41 Correct 104 ms 174976 KB Output is correct
42 Correct 113 ms 176420 KB Output is correct
43 Correct 146 ms 179992 KB Output is correct
44 Correct 144 ms 181780 KB Output is correct
45 Correct 101 ms 170324 KB Output is correct
46 Correct 97 ms 164688 KB Output is correct
47 Correct 138 ms 180304 KB Output is correct
48 Correct 137 ms 181328 KB Output is correct
49 Correct 64 ms 147796 KB Output is correct
50 Correct 69 ms 147792 KB Output is correct
51 Correct 62 ms 147792 KB Output is correct
52 Correct 62 ms 147540 KB Output is correct
53 Correct 61 ms 147792 KB Output is correct
54 Correct 58 ms 147796 KB Output is correct
55 Correct 62 ms 147796 KB Output is correct
56 Correct 62 ms 147792 KB Output is correct
57 Correct 66 ms 147796 KB Output is correct
58 Correct 67 ms 147792 KB Output is correct
59 Correct 66 ms 147796 KB Output is correct
60 Correct 61 ms 147792 KB Output is correct
61 Correct 360 ms 246416 KB Output is correct
62 Correct 542 ms 354680 KB Output is correct
63 Correct 553 ms 355760 KB Output is correct
64 Correct 570 ms 355696 KB Output is correct
65 Correct 175 ms 226256 KB Output is correct
66 Correct 273 ms 303376 KB Output is correct
67 Correct 286 ms 307028 KB Output is correct
68 Correct 68 ms 147536 KB Output is correct
69 Correct 66 ms 147544 KB Output is correct
70 Correct 70 ms 148052 KB Output is correct
71 Correct 72 ms 148048 KB Output is correct
72 Correct 62 ms 147792 KB Output is correct
73 Correct 500 ms 439220 KB Output is correct
74 Correct 534 ms 439052 KB Output is correct
75 Correct 478 ms 358084 KB Output is correct
76 Correct 490 ms 358128 KB Output is correct
77 Execution timed out 5050 ms 537940 KB Time limit exceeded
78 Halted 0 ms 0 KB -