Submission #906271

# Submission time Handle Problem Language Result Execution time Memory
906271 2024-01-13T22:24:19 Z vjudge1 Rectangles (IOI19_rect) C++17
72 / 100
5000 ms 977276 KB
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;



long long count_rectangles(std::vector<std::vector<int> > a) {
	int n = sz(a);
	int m = sz(a[0]);
	vector<vector<map<int,int>>> rowf(n,vector<map<int,int>>(m));
	rep(i,0,n){
		vector<pii> stack;
		rep(j,0,m){
			
			while(sz(stack) && stack.back().F < a[i][j]){
				if(stack.back().S+1 <= j-1) {
					rowf[i][stack.back().S+1][j-1]=-1;
					// cout<<"push "<<(stack.back().S+1)<<" to "<<j-1<<endl;
				}
				stack.pop_back();
			}
			if(sz(stack) && stack.back().S+1 <= j-1) {
				// cout<<"push "<<(stack.back().S+1)<<" to "<<j-1<<endl;
				rowf[i][stack.back().S+1][j-1]=-1;
			}
			while(sz(stack) && stack.back().F == a[i][j]) stack.pop_back();
			stack.pb({a[i][j],j});
		}
	}

	vector<vector<map<int,int>>> colf(n,vector<map<int,int>>(m));
	rep(j,0,m){
		vector<pii> stack;
		rep(i,0,n){
			while(sz(stack) && stack.back().F < a[i][j]){
				if(stack.back().S+1<=i-1) colf[stack.back().S+1][j][i-1]=-1;
				stack.pop_back();
			}
			if(sz(stack) && stack.back().S+1<=i-1) colf[stack.back().S+1][j][i-1]=-1;
			while(sz(stack) && stack.back().F == a[i][j]) stack.pop_back();
			stack.pb({a[i][j],i});
		}
	}

	
	rep(i,0,n)rep(j,0,m){
		for(auto p : rowf[i][j]){
			if(p.S == -1){
				int k = i;
				while(k<n && rowf[k][j].count(p.F)) k++;
				rep(l,i,k) rowf[l][j][p.F]=k-1;
			}
		}
		for(auto p : colf[i][j]){
			if(p.S == -1){
				int k = j;
				while(k<m && colf[i][k].count(p.F)) k++;
				rep(l,j,k) colf[i][l][p.F]=k-1;
			}
		}
	}

	// rep(i,0,n){
	// 	rep(j,0,m){
	// 		cout<<i<<' '<<j<<" rows:";
	// 		for(pii x : rowf[i][j]) cout<<' '<<x.F<<","<<x.S;
	// 		cout<<endl;
	// 		cout<<i<<' '<<j<<" cols:";
	// 		for(pii x : colf[i][j]) cout<<' '<<x.F<<","<<x.S;
	// 		cout<<endl;
	// 	}
	// }

	ll ans = 0;
	rep(i,0,n){
		rep(j,0,m){
			for(pii l : colf[i][j])for(pii r : rowf[i][j]){
				// [i, r.F], r.S tells how far we go on other
				// [j, l.F], l.S tells how far we go on other
				bool good = l.S>=r.F && r.S >= l.F;
				// cout<<i<<' '<<j<<" ("<<l.F<<','<<l.S<<") ("<<r.F<<','<<r.S<<") "<<good<<endl;
				ans += good;
			}
		}
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 500 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 500 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 432 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 1628 KB Output is correct
23 Correct 2 ms 1628 KB Output is correct
24 Correct 2 ms 1628 KB Output is correct
25 Correct 2 ms 1116 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 3 ms 1640 KB Output is correct
28 Correct 3 ms 1572 KB Output is correct
29 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 500 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1628 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 3 ms 1628 KB Output is correct
22 Correct 3 ms 1640 KB Output is correct
23 Correct 3 ms 1572 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 0 ms 432 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 12 ms 8284 KB Output is correct
31 Correct 14 ms 8284 KB Output is correct
32 Correct 11 ms 8540 KB Output is correct
33 Correct 7 ms 5980 KB Output is correct
34 Correct 14 ms 8028 KB Output is correct
35 Correct 20 ms 8540 KB Output is correct
36 Correct 14 ms 8028 KB Output is correct
37 Correct 16 ms 7804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 500 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1628 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 3 ms 1628 KB Output is correct
22 Correct 3 ms 1640 KB Output is correct
23 Correct 3 ms 1572 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 12 ms 8284 KB Output is correct
26 Correct 14 ms 8284 KB Output is correct
27 Correct 11 ms 8540 KB Output is correct
28 Correct 7 ms 5980 KB Output is correct
29 Correct 14 ms 8028 KB Output is correct
30 Correct 20 ms 8540 KB Output is correct
31 Correct 14 ms 8028 KB Output is correct
32 Correct 16 ms 7804 KB Output is correct
33 Correct 0 ms 432 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 119 ms 76372 KB Output is correct
39 Correct 152 ms 76460 KB Output is correct
40 Correct 121 ms 76280 KB Output is correct
41 Correct 556 ms 76464 KB Output is correct
42 Correct 203 ms 99244 KB Output is correct
43 Correct 202 ms 99156 KB Output is correct
44 Correct 205 ms 99748 KB Output is correct
45 Correct 202 ms 93228 KB Output is correct
46 Correct 108 ms 62576 KB Output is correct
47 Correct 119 ms 68948 KB Output is correct
48 Correct 244 ms 96536 KB Output is correct
49 Correct 262 ms 99240 KB Output is correct
50 Correct 133 ms 49492 KB Output is correct
51 Correct 118 ms 49492 KB Output is correct
52 Correct 237 ms 94292 KB Output is correct
53 Correct 250 ms 95804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1628 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 2 ms 1628 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 2 ms 1628 KB Output is correct
9 Correct 2 ms 1484 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 698 ms 364564 KB Output is correct
8 Correct 2221 ms 791372 KB Output is correct
9 Correct 1532 ms 795272 KB Output is correct
10 Correct 1492 ms 795696 KB Output is correct
11 Correct 293 ms 320724 KB Output is correct
12 Correct 568 ms 608992 KB Output is correct
13 Correct 600 ms 649212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 500 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1628 KB Output is correct
20 Correct 2 ms 1116 KB Output is correct
21 Correct 3 ms 1628 KB Output is correct
22 Correct 3 ms 1640 KB Output is correct
23 Correct 3 ms 1572 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 12 ms 8284 KB Output is correct
26 Correct 14 ms 8284 KB Output is correct
27 Correct 11 ms 8540 KB Output is correct
28 Correct 7 ms 5980 KB Output is correct
29 Correct 14 ms 8028 KB Output is correct
30 Correct 20 ms 8540 KB Output is correct
31 Correct 14 ms 8028 KB Output is correct
32 Correct 16 ms 7804 KB Output is correct
33 Correct 119 ms 76372 KB Output is correct
34 Correct 152 ms 76460 KB Output is correct
35 Correct 121 ms 76280 KB Output is correct
36 Correct 556 ms 76464 KB Output is correct
37 Correct 203 ms 99244 KB Output is correct
38 Correct 202 ms 99156 KB Output is correct
39 Correct 205 ms 99748 KB Output is correct
40 Correct 202 ms 93228 KB Output is correct
41 Correct 108 ms 62576 KB Output is correct
42 Correct 119 ms 68948 KB Output is correct
43 Correct 244 ms 96536 KB Output is correct
44 Correct 262 ms 99240 KB Output is correct
45 Correct 133 ms 49492 KB Output is correct
46 Correct 118 ms 49492 KB Output is correct
47 Correct 237 ms 94292 KB Output is correct
48 Correct 250 ms 95804 KB Output is correct
49 Correct 2 ms 1628 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 1 ms 1116 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 2 ms 1628 KB Output is correct
54 Correct 2 ms 1628 KB Output is correct
55 Correct 2 ms 1624 KB Output is correct
56 Correct 2 ms 1628 KB Output is correct
57 Correct 2 ms 1484 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 2 ms 1116 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 698 ms 364564 KB Output is correct
62 Correct 2221 ms 791372 KB Output is correct
63 Correct 1532 ms 795272 KB Output is correct
64 Correct 1492 ms 795696 KB Output is correct
65 Correct 293 ms 320724 KB Output is correct
66 Correct 568 ms 608992 KB Output is correct
67 Correct 600 ms 649212 KB Output is correct
68 Correct 0 ms 432 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 2060 ms 976644 KB Output is correct
74 Correct 2424 ms 976836 KB Output is correct
75 Correct 1723 ms 977276 KB Output is correct
76 Execution timed out 5124 ms 976724 KB Time limit exceeded
77 Halted 0 ms 0 KB -