Submission #906278

# Submission time Handle Problem Language Result Execution time Memory
906278 2024-01-13T22:42:30 Z vjudge1 Rectangles (IOI19_rect) C++17
72 / 100
2236 ms 1048576 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]){
				// [j, l.F], l.S tells how far we go on other
				// [i, r.F], r.S tells how far we go on other
				if(l.S < r.F) break;
				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 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 760 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 760 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 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 1648 KB Output is correct
24 Correct 2 ms 1824 KB Output is correct
25 Correct 2 ms 1112 KB Output is correct
26 Correct 3 ms 1624 KB Output is correct
27 Correct 3 ms 1624 KB Output is correct
28 Correct 3 ms 1568 KB Output is correct
29 Correct 2 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1648 KB Output is correct
19 Correct 2 ms 1824 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 3 ms 1624 KB Output is correct
22 Correct 3 ms 1624 KB Output is correct
23 Correct 3 ms 1568 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 760 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 12 ms 8284 KB Output is correct
31 Correct 12 ms 8280 KB Output is correct
32 Correct 12 ms 8284 KB Output is correct
33 Correct 8 ms 5820 KB Output is correct
34 Correct 15 ms 8028 KB Output is correct
35 Correct 17 ms 8456 KB Output is correct
36 Correct 15 ms 8028 KB Output is correct
37 Correct 18 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1648 KB Output is correct
19 Correct 2 ms 1824 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 3 ms 1624 KB Output is correct
22 Correct 3 ms 1624 KB Output is correct
23 Correct 3 ms 1568 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 12 ms 8284 KB Output is correct
26 Correct 12 ms 8280 KB Output is correct
27 Correct 12 ms 8284 KB Output is correct
28 Correct 8 ms 5820 KB Output is correct
29 Correct 15 ms 8028 KB Output is correct
30 Correct 17 ms 8456 KB Output is correct
31 Correct 15 ms 8028 KB Output is correct
32 Correct 18 ms 8028 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 760 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 128 ms 75012 KB Output is correct
39 Correct 150 ms 74980 KB Output is correct
40 Correct 128 ms 75088 KB Output is correct
41 Correct 160 ms 74964 KB Output is correct
42 Correct 209 ms 97904 KB Output is correct
43 Correct 222 ms 97700 KB Output is correct
44 Correct 216 ms 98276 KB Output is correct
45 Correct 225 ms 91732 KB Output is correct
46 Correct 132 ms 62468 KB Output is correct
47 Correct 133 ms 68948 KB Output is correct
48 Correct 241 ms 95832 KB Output is correct
49 Correct 265 ms 97440 KB Output is correct
50 Correct 146 ms 49124 KB Output is correct
51 Correct 125 ms 48896 KB Output is correct
52 Correct 237 ms 93264 KB Output is correct
53 Correct 244 ms 93944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 2 ms 1368 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 2 ms 1624 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 2 ms 1624 KB Output is correct
9 Correct 2 ms 1628 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 760 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 711 ms 362084 KB Output is correct
8 Correct 1598 ms 785816 KB Output is correct
9 Correct 1530 ms 789440 KB Output is correct
10 Correct 1514 ms 789732 KB Output is correct
11 Correct 304 ms 317916 KB Output is correct
12 Correct 581 ms 603308 KB Output is correct
13 Correct 603 ms 643376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1648 KB Output is correct
19 Correct 2 ms 1824 KB Output is correct
20 Correct 2 ms 1112 KB Output is correct
21 Correct 3 ms 1624 KB Output is correct
22 Correct 3 ms 1624 KB Output is correct
23 Correct 3 ms 1568 KB Output is correct
24 Correct 2 ms 1112 KB Output is correct
25 Correct 12 ms 8284 KB Output is correct
26 Correct 12 ms 8280 KB Output is correct
27 Correct 12 ms 8284 KB Output is correct
28 Correct 8 ms 5820 KB Output is correct
29 Correct 15 ms 8028 KB Output is correct
30 Correct 17 ms 8456 KB Output is correct
31 Correct 15 ms 8028 KB Output is correct
32 Correct 18 ms 8028 KB Output is correct
33 Correct 128 ms 75012 KB Output is correct
34 Correct 150 ms 74980 KB Output is correct
35 Correct 128 ms 75088 KB Output is correct
36 Correct 160 ms 74964 KB Output is correct
37 Correct 209 ms 97904 KB Output is correct
38 Correct 222 ms 97700 KB Output is correct
39 Correct 216 ms 98276 KB Output is correct
40 Correct 225 ms 91732 KB Output is correct
41 Correct 132 ms 62468 KB Output is correct
42 Correct 133 ms 68948 KB Output is correct
43 Correct 241 ms 95832 KB Output is correct
44 Correct 265 ms 97440 KB Output is correct
45 Correct 146 ms 49124 KB Output is correct
46 Correct 125 ms 48896 KB Output is correct
47 Correct 237 ms 93264 KB Output is correct
48 Correct 244 ms 93944 KB Output is correct
49 Correct 2 ms 1624 KB Output is correct
50 Correct 2 ms 1368 KB Output is correct
51 Correct 1 ms 1112 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 2 ms 1628 KB Output is correct
54 Correct 2 ms 1624 KB Output is correct
55 Correct 2 ms 1624 KB Output is correct
56 Correct 2 ms 1624 KB Output is correct
57 Correct 2 ms 1628 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 2 ms 1112 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 711 ms 362084 KB Output is correct
62 Correct 1598 ms 785816 KB Output is correct
63 Correct 1530 ms 789440 KB Output is correct
64 Correct 1514 ms 789732 KB Output is correct
65 Correct 304 ms 317916 KB Output is correct
66 Correct 581 ms 603308 KB Output is correct
67 Correct 603 ms 643376 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 760 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 1 ms 344 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1809 ms 930408 KB Output is correct
74 Correct 2236 ms 929972 KB Output is correct
75 Correct 1668 ms 930128 KB Output is correct
76 Correct 2110 ms 930136 KB Output is correct
77 Runtime error 1136 ms 1048576 KB Execution killed with signal 9
78 Halted 0 ms 0 KB -