Submission #1067944

# Submission time Handle Problem Language Result Execution time Memory
1067944 2024-08-21T05:54:02 Z LittleOrange Rectangles (IOI19_rect) C++17
59 / 100
5000 ms 42152 KB
#include "rect.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
using lll = long long;

long long count_rectangles(std::vector<std::vector<int> > a) {
	ll n = a.size(), m = a[0].size();
	if (n<3||m<3) return 0;
	vector<vector<pair<ll,ll>>> row(n),col(m);
	for(ll i = 0;i<n;i++){
		vector<pair<ll,ll>> st;
		for(ll j = 0;j<m;j++){
			while(st.size()&&st.back().first<a[i][j]){
				if(j>st.back().second+1)row[i].push_back({st.back().second,j});
				st.pop_back();
			}
			if(st.size()){
				if(j>st.back().second+1)row[i].push_back({st.back().second,j});
			}
			if (st.size()&&st.back().first==a[i][j]) st.pop_back();
			st.push_back({a[i][j],j});
		}
	}
	for(ll j = 0;j<m;j++){
		vector<pair<ll,ll>> st;
		for(ll i = 0;i<n;i++){
			while(st.size()&&st.back().first<a[i][j]){
				if(i>st.back().second+1)col[j].push_back({st.back().second,i});
				st.pop_back();
			}
			if(st.size()){
				if(i>st.back().second+1)col[j].push_back({st.back().second,i});
			}
			if (st.size()&&st.back().first==a[i][j]) st.pop_back();
			st.push_back({a[i][j],i});
		}
	}
	for(auto &o : row) sort(o.begin(),o.end());
	for(auto &o : col) sort(o.begin(),o.end());
	lll ans = 0;
	for(ll r1 = 1;r1<n-1;r1++){
		vector<pair<ll,ll>> cur = row[r1];
		for(ll r2 = r1;r2<n-1;r2++){
			if(r2>r1){
				vector<pair<ll,ll>> nw;
				for(auto &o : cur){
					if (binary_search(row[r2].begin(),row[r2].end(),o)){
						nw.push_back(o);
					}
				}
				nw.swap(cur);
			}
			pair<ll,ll> t = {r1-1,r2+1};
			vector<ll> ok(m,0);
			for(ll i = 0;i<m;i++) ok[i] = binary_search(col[i].begin(),col[i].end(),t);
			vector<ll> p(m+1,0);
			for(ll i = 0;i<m;i++) p[i+1] = p[i]+ok[i];
			for(auto &o : cur){
				if (p[o.second]-p[o.first+1]==(o.second-o.first-1)) ans++;
			}
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 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 0 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 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 0 ms 348 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 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 0 ms 348 KB Output is correct
22 Correct 5 ms 600 KB Output is correct
23 Correct 5 ms 604 KB Output is correct
24 Correct 7 ms 648 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 5 ms 604 KB Output is correct
27 Correct 5 ms 604 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 3 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 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 0 ms 348 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 7 ms 648 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 0 ms 348 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 0 ms 348 KB Output is correct
30 Correct 97 ms 1372 KB Output is correct
31 Correct 98 ms 1556 KB Output is correct
32 Correct 99 ms 1552 KB Output is correct
33 Correct 43 ms 1112 KB Output is correct
34 Correct 52 ms 1368 KB Output is correct
35 Correct 53 ms 1372 KB Output is correct
36 Correct 61 ms 1564 KB Output is correct
37 Correct 58 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 7 ms 648 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 97 ms 1372 KB Output is correct
26 Correct 98 ms 1556 KB Output is correct
27 Correct 99 ms 1552 KB Output is correct
28 Correct 43 ms 1112 KB Output is correct
29 Correct 52 ms 1368 KB Output is correct
30 Correct 53 ms 1372 KB Output is correct
31 Correct 61 ms 1564 KB Output is correct
32 Correct 58 ms 1368 KB Output is correct
33 Correct 0 ms 348 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 0 ms 348 KB Output is correct
38 Correct 2126 ms 10084 KB Output is correct
39 Correct 2132 ms 10084 KB Output is correct
40 Correct 2105 ms 10064 KB Output is correct
41 Correct 1995 ms 10088 KB Output is correct
42 Correct 4978 ms 15580 KB Output is correct
43 Correct 4727 ms 18768 KB Output is correct
44 Correct 4830 ms 19140 KB Output is correct
45 Correct 4329 ms 18456 KB Output is correct
46 Correct 2079 ms 8128 KB Output is correct
47 Correct 2309 ms 10836 KB Output is correct
48 Correct 2826 ms 17376 KB Output is correct
49 Correct 2896 ms 19276 KB Output is correct
50 Correct 1203 ms 9880 KB Output is correct
51 Correct 706 ms 9876 KB Output is correct
52 Correct 2932 ms 18116 KB Output is correct
53 Correct 2773 ms 19100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 652 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Execution timed out 5045 ms 42152 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 7 ms 648 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 5 ms 604 KB Output is correct
23 Correct 4 ms 640 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 97 ms 1372 KB Output is correct
26 Correct 98 ms 1556 KB Output is correct
27 Correct 99 ms 1552 KB Output is correct
28 Correct 43 ms 1112 KB Output is correct
29 Correct 52 ms 1368 KB Output is correct
30 Correct 53 ms 1372 KB Output is correct
31 Correct 61 ms 1564 KB Output is correct
32 Correct 58 ms 1368 KB Output is correct
33 Correct 2126 ms 10084 KB Output is correct
34 Correct 2132 ms 10084 KB Output is correct
35 Correct 2105 ms 10064 KB Output is correct
36 Correct 1995 ms 10088 KB Output is correct
37 Correct 4978 ms 15580 KB Output is correct
38 Correct 4727 ms 18768 KB Output is correct
39 Correct 4830 ms 19140 KB Output is correct
40 Correct 4329 ms 18456 KB Output is correct
41 Correct 2079 ms 8128 KB Output is correct
42 Correct 2309 ms 10836 KB Output is correct
43 Correct 2826 ms 17376 KB Output is correct
44 Correct 2896 ms 19276 KB Output is correct
45 Correct 1203 ms 9880 KB Output is correct
46 Correct 706 ms 9876 KB Output is correct
47 Correct 2932 ms 18116 KB Output is correct
48 Correct 2773 ms 19100 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 652 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Execution timed out 5045 ms 42152 KB Time limit exceeded
62 Halted 0 ms 0 KB -