Submission #1034058

# Submission time Handle Problem Language Result Execution time Memory
1034058 2024-07-25T09:17:23 Z AmirAli_H1 Rectangles (IOI19_rect) C++17
37 / 100
5000 ms 76820 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];

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]]);
		}
	}
	
	ll ans = 0;
	for (int l1 = 1; l1 < n - 1; l1++) {
		for (int r1 = l1; r1 < n - 1; r1++) {
			for (int l2 = 1; l2 < m - 1; l2++) {
				for (int r2 = l2; r2 < m - 1; r2++) {
					if (ok(l1, r1, l2, r2)) ans++;
				}
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 36 ms 1880 KB Output is correct
23 Correct 42 ms 1880 KB Output is correct
24 Correct 48 ms 1884 KB Output is correct
25 Correct 31 ms 1880 KB Output is correct
26 Correct 38 ms 1884 KB Output is correct
27 Correct 30 ms 1884 KB Output is correct
28 Correct 31 ms 1884 KB Output is correct
29 Correct 8 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 36 ms 1880 KB Output is correct
18 Correct 42 ms 1880 KB Output is correct
19 Correct 48 ms 1884 KB Output is correct
20 Correct 31 ms 1880 KB Output is correct
21 Correct 38 ms 1884 KB Output is correct
22 Correct 30 ms 1884 KB Output is correct
23 Correct 31 ms 1884 KB Output is correct
24 Correct 8 ms 1628 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 1453 ms 4696 KB Output is correct
31 Correct 1409 ms 4952 KB Output is correct
32 Correct 1341 ms 4880 KB Output is correct
33 Correct 1210 ms 4648 KB Output is correct
34 Correct 1187 ms 4692 KB Output is correct
35 Correct 1178 ms 4876 KB Output is correct
36 Correct 1255 ms 4844 KB Output is correct
37 Correct 1172 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 36 ms 1880 KB Output is correct
18 Correct 42 ms 1880 KB Output is correct
19 Correct 48 ms 1884 KB Output is correct
20 Correct 31 ms 1880 KB Output is correct
21 Correct 38 ms 1884 KB Output is correct
22 Correct 30 ms 1884 KB Output is correct
23 Correct 31 ms 1884 KB Output is correct
24 Correct 8 ms 1628 KB Output is correct
25 Correct 1453 ms 4696 KB Output is correct
26 Correct 1409 ms 4952 KB Output is correct
27 Correct 1341 ms 4880 KB Output is correct
28 Correct 1210 ms 4648 KB Output is correct
29 Correct 1187 ms 4692 KB Output is correct
30 Correct 1178 ms 4876 KB Output is correct
31 Correct 1255 ms 4844 KB Output is correct
32 Correct 1172 ms 4864 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 0 ms 604 KB Output is correct
38 Execution timed out 5043 ms 26292 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1694 ms 628 KB Output is correct
2 Correct 1131 ms 604 KB Output is correct
3 Correct 10 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 11 ms 644 KB Output is correct
6 Correct 11 ms 604 KB Output is correct
7 Correct 11 ms 604 KB Output is correct
8 Correct 11 ms 604 KB Output is correct
9 Correct 11 ms 644 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Execution timed out 5080 ms 76820 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 36 ms 1880 KB Output is correct
18 Correct 42 ms 1880 KB Output is correct
19 Correct 48 ms 1884 KB Output is correct
20 Correct 31 ms 1880 KB Output is correct
21 Correct 38 ms 1884 KB Output is correct
22 Correct 30 ms 1884 KB Output is correct
23 Correct 31 ms 1884 KB Output is correct
24 Correct 8 ms 1628 KB Output is correct
25 Correct 1453 ms 4696 KB Output is correct
26 Correct 1409 ms 4952 KB Output is correct
27 Correct 1341 ms 4880 KB Output is correct
28 Correct 1210 ms 4648 KB Output is correct
29 Correct 1187 ms 4692 KB Output is correct
30 Correct 1178 ms 4876 KB Output is correct
31 Correct 1255 ms 4844 KB Output is correct
32 Correct 1172 ms 4864 KB Output is correct
33 Execution timed out 5043 ms 26292 KB Time limit exceeded
34 Halted 0 ms 0 KB -