Submission #155815

# Submission time Handle Problem Language Result Execution time Memory
155815 2019-09-30T16:21:54 Z vanic Rectangles (IOI19_rect) C++14
59 / 100
5000 ms 437968 KB
#include "rect.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#include <stack>
#include <set>
#include <array>
 
using namespace std;
 
typedef long long ll;
const int maxn=2503;
 
int n, m;
int l[maxn][maxn];
//vector < int > r[maxn][maxn], c[maxn][maxn];
unordered_map < ll, int > r, c;
int rind[maxn][maxn], cind[maxn][maxn];
pair < int, int > red[maxn][maxn], stup[maxn][maxn];
int bio2[maxn][maxn], bio3[maxn][maxn];
vector < array < int, 4 > > bio;

inline ll hashiraj(ll a, ll b, ll c){
	return a*maxn*maxn+b*maxn+c;
}
 
void upd1(int x){
	stack < pair < int, int > > q;
	q.push(make_pair(1e8, -1));
	for(int i=0; i<m; i++){
		while(q.top().first<=l[x][i]){
			q.pop();
		}
		red[x][i].first=q.top().second+1;
		q.push(make_pair(l[x][i], i));
	}
	while(!q.empty()){
		q.pop();
	}
	q.push(make_pair(1e8, m));
	for(int i=m-1; i>-1; i--){
		while(q.top().first<=l[x][i]){
			q.pop();
		}
		red[x][i].second=q.top().second-1;
		if(bio2[red[x][i].first][red[x][i].second]!=x+1){
			bio2[red[x][i].first][red[x][i].second]=x+1;
			rind[red[x][i].first][red[x][i].second]++;
			r[hashiraj(red[x][i].first, red[x][i].second, x)]=rind[red[x][i].first][red[x][i].second];
		}
		q.push(make_pair(l[x][i], i));
	}
}
 
void upd2(int x){
	stack < pair < int, int > > q;
	q.push(make_pair(1e8, -1));
	for(int i=0; i<n; i++){
		while(q.top().first<=l[i][x]){
			q.pop();
		}
		stup[i][x].first=q.top().second+1;
		q.push(make_pair(l[i][x], i));
	}
	while(!q.empty()){
		q.pop();
	}
	q.push(make_pair(1e8, n));
	for(int i=n-1; i>-1; i--){
		while(q.top().first<=l[i][x]){
			q.pop();
		}
		stup[i][x].second=q.top().second-1;
		if(bio3[stup[i][x].first][stup[i][x].second]!=x+1){
			bio3[stup[i][x].first][stup[i][x].second]=x+1;
			cind[stup[i][x].first][stup[i][x].second]++;
			c[hashiraj(stup[i][x].first, stup[i][x].second, x)]=cind[stup[i][x].first][stup[i][x].second];
		}
		q.push(make_pair(l[i][x], i));
	}
}
 
 
int binary(int x, vector < int > &l){
	int lo=0, hi=l.size(), mid;
	while(lo<hi){
		mid=(lo+hi)/2;
		if(l[mid]<x){
			lo=mid+1;
		}
		else{
			hi=mid;
		}
	}
	return lo;
}
 
void provjeri(int x, int y){
	int r1, r2, c1, c2;
	r1=red[x][y].first;
	r2=red[x][y].second;
	c1=stup[x][y].first;
	c2=stup[x][y].second;
	if(r1==0 || c1==0 || r2==m-1 || c2==n-1){
		return;
	}
//	int pos1=binary(c1, r[r1][r2]);
//	int pos2=binary(r1, c[c1][c2]);
	if(r[hashiraj(r1, r2, c2)]!=0 && r[hashiraj(r1, r2, c1)]!=0
	&& c[hashiraj(c1, c2, r2)]!=0 && c[hashiraj(c1, c2, r1)]!=0
	&& r[hashiraj(r1, r2, c2)]-r[hashiraj(r1, r2, c1)]==c2-c1 && c[hashiraj(c1, c2, r2)]-c[hashiraj(c1, c2, r1)]==r2-r1){
		bio.push_back({r1, r2, c1, c2});
	}
}
 
long long count_rectangles(vector < vector < int > > a){
	n=a.size();
	m=a[0].size();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			l[i][j]=a[i][j];
		}
	}
	for(int i=0; i<n; i++){
		upd1(i);
	}
	for(int i=0; i<m; i++){
		upd2(i);
	}
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){
			provjeri(i, j);
		}
	}
	sort(bio.begin(), bio.end());
	bio.erase(unique(bio.begin(), bio.end()), bio.end());
	return bio.size();
}
 
/*
int main(){
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			scanf("%d", &l[i][j]);
		}
	}
	for(int i=0; i<n; i++){
		upd1(i);
	}
	for(int i=0; i<m; i++){
		upd2(i);
	}
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){
			provjeri(i, j);
		}
	}
	sort(bio.begin(), bio.end());
	bio.erase(unique(bio.begin(), bio.end()), bio.end());
	printf("%d\n", (int)bio.size());
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1320 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 1272 KB Output is correct
20 Correct 2 ms 760 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1320 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 8 ms 3576 KB Output is correct
18 Correct 9 ms 3448 KB Output is correct
19 Correct 9 ms 3448 KB Output is correct
20 Correct 6 ms 3064 KB Output is correct
21 Correct 10 ms 3580 KB Output is correct
22 Correct 9 ms 3448 KB Output is correct
23 Correct 10 ms 3576 KB Output is correct
24 Correct 6 ms 2676 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 1272 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1320 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 8 ms 3576 KB Output is correct
18 Correct 9 ms 3448 KB Output is correct
19 Correct 9 ms 3448 KB Output is correct
20 Correct 6 ms 3064 KB Output is correct
21 Correct 10 ms 3580 KB Output is correct
22 Correct 9 ms 3448 KB Output is correct
23 Correct 10 ms 3576 KB Output is correct
24 Correct 6 ms 2676 KB Output is correct
25 Correct 38 ms 11812 KB Output is correct
26 Correct 36 ms 11812 KB Output is correct
27 Correct 40 ms 11832 KB Output is correct
28 Correct 31 ms 9464 KB Output is correct
29 Correct 47 ms 12196 KB Output is correct
30 Correct 47 ms 12200 KB Output is correct
31 Correct 42 ms 11428 KB Output is correct
32 Correct 45 ms 11092 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 1272 KB Output is correct
36 Correct 2 ms 760 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1320 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 8 ms 3576 KB Output is correct
18 Correct 9 ms 3448 KB Output is correct
19 Correct 9 ms 3448 KB Output is correct
20 Correct 6 ms 3064 KB Output is correct
21 Correct 10 ms 3580 KB Output is correct
22 Correct 9 ms 3448 KB Output is correct
23 Correct 10 ms 3576 KB Output is correct
24 Correct 6 ms 2676 KB Output is correct
25 Correct 38 ms 11812 KB Output is correct
26 Correct 36 ms 11812 KB Output is correct
27 Correct 40 ms 11832 KB Output is correct
28 Correct 31 ms 9464 KB Output is correct
29 Correct 47 ms 12196 KB Output is correct
30 Correct 47 ms 12200 KB Output is correct
31 Correct 42 ms 11428 KB Output is correct
32 Correct 45 ms 11092 KB Output is correct
33 Correct 528 ms 84320 KB Output is correct
34 Correct 531 ms 84204 KB Output is correct
35 Correct 529 ms 84332 KB Output is correct
36 Correct 524 ms 84336 KB Output is correct
37 Correct 564 ms 90800 KB Output is correct
38 Correct 565 ms 90604 KB Output is correct
39 Correct 630 ms 90752 KB Output is correct
40 Correct 652 ms 87936 KB Output is correct
41 Correct 266 ms 52272 KB Output is correct
42 Correct 428 ms 60284 KB Output is correct
43 Correct 1072 ms 92828 KB Output is correct
44 Correct 986 ms 93488 KB Output is correct
45 Correct 515 ms 54132 KB Output is correct
46 Correct 396 ms 49868 KB Output is correct
47 Correct 904 ms 86564 KB Output is correct
48 Correct 1149 ms 86852 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 3 ms 1272 KB Output is correct
52 Correct 2 ms 760 KB Output is correct
53 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 21496 KB Output is correct
2 Correct 22 ms 18168 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 24 ms 19320 KB Output is correct
6 Correct 24 ms 18936 KB Output is correct
7 Correct 23 ms 19064 KB Output is correct
8 Correct 26 ms 17900 KB Output is correct
9 Correct 22 ms 17436 KB Output is correct
10 Correct 13 ms 11000 KB Output is correct
11 Correct 19 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2405 ms 224980 KB Output is correct
3 Execution timed out 5058 ms 437968 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 4 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 4 ms 1272 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 4 ms 1272 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 2 ms 888 KB Output is correct
9 Correct 3 ms 1272 KB Output is correct
10 Correct 3 ms 1320 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 3 ms 1272 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 8 ms 3576 KB Output is correct
18 Correct 9 ms 3448 KB Output is correct
19 Correct 9 ms 3448 KB Output is correct
20 Correct 6 ms 3064 KB Output is correct
21 Correct 10 ms 3580 KB Output is correct
22 Correct 9 ms 3448 KB Output is correct
23 Correct 10 ms 3576 KB Output is correct
24 Correct 6 ms 2676 KB Output is correct
25 Correct 38 ms 11812 KB Output is correct
26 Correct 36 ms 11812 KB Output is correct
27 Correct 40 ms 11832 KB Output is correct
28 Correct 31 ms 9464 KB Output is correct
29 Correct 47 ms 12196 KB Output is correct
30 Correct 47 ms 12200 KB Output is correct
31 Correct 42 ms 11428 KB Output is correct
32 Correct 45 ms 11092 KB Output is correct
33 Correct 528 ms 84320 KB Output is correct
34 Correct 531 ms 84204 KB Output is correct
35 Correct 529 ms 84332 KB Output is correct
36 Correct 524 ms 84336 KB Output is correct
37 Correct 564 ms 90800 KB Output is correct
38 Correct 565 ms 90604 KB Output is correct
39 Correct 630 ms 90752 KB Output is correct
40 Correct 652 ms 87936 KB Output is correct
41 Correct 266 ms 52272 KB Output is correct
42 Correct 428 ms 60284 KB Output is correct
43 Correct 1072 ms 92828 KB Output is correct
44 Correct 986 ms 93488 KB Output is correct
45 Correct 515 ms 54132 KB Output is correct
46 Correct 396 ms 49868 KB Output is correct
47 Correct 904 ms 86564 KB Output is correct
48 Correct 1149 ms 86852 KB Output is correct
49 Correct 25 ms 21496 KB Output is correct
50 Correct 22 ms 18168 KB Output is correct
51 Correct 3 ms 632 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 24 ms 19320 KB Output is correct
54 Correct 24 ms 18936 KB Output is correct
55 Correct 23 ms 19064 KB Output is correct
56 Correct 26 ms 17900 KB Output is correct
57 Correct 22 ms 17436 KB Output is correct
58 Correct 13 ms 11000 KB Output is correct
59 Correct 19 ms 16248 KB Output is correct
60 Correct 2 ms 632 KB Output is correct
61 Correct 2405 ms 224980 KB Output is correct
62 Execution timed out 5058 ms 437968 KB Time limit exceeded
63 Halted 0 ms 0 KB -