# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
155822 |
2019-09-30T16:37:10 Z |
vanic |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
457444 KB |
#include "rect.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#include <stack>
#include <set>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn=2503, mod=200002027;
int n, m;
int l[maxn][maxn];
//vector < int > r[maxn][maxn], c[maxn][maxn];
unordered_map < int, 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;
bitset < mod > bio;
inline int hashiraj(ll a, ll b, ll c){
return (a*maxn*maxn+b*maxn+c)%mod;
}
inline int hashah(ll a, ll b, ll c, ll d){
return (a*maxn*maxn*maxn+b*maxn*maxn+c*maxn+d)%mod;
}
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));
}
}
bool 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 0;
}
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){
if(!bio[hashah(r1, r2, c1, c2)]){
bio[hashah(r1, r2, c1, c2)]=1;
return 1;
}
}
return 0;
}
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);
}
int br=0;
for(int i=1; i<n-1; i++){
for(int j=1; j<m-1; j++){
br+=provjeri(i, j);
}
}
return br;
}
/*
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 |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
1656 KB |
Output is correct |
3 |
Correct |
3 ms |
1656 KB |
Output is correct |
4 |
Correct |
3 ms |
1656 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
1788 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1784 KB |
Output is correct |
10 |
Correct |
4 ms |
1756 KB |
Output is correct |
11 |
Correct |
3 ms |
1784 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
1400 KB |
Output is correct |
20 |
Correct |
1 ms |
760 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
1656 KB |
Output is correct |
3 |
Correct |
3 ms |
1656 KB |
Output is correct |
4 |
Correct |
3 ms |
1656 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
1788 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1784 KB |
Output is correct |
10 |
Correct |
4 ms |
1756 KB |
Output is correct |
11 |
Correct |
3 ms |
1784 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 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 |
10 ms |
5240 KB |
Output is correct |
18 |
Correct |
10 ms |
5244 KB |
Output is correct |
19 |
Correct |
10 ms |
5240 KB |
Output is correct |
20 |
Correct |
8 ms |
4856 KB |
Output is correct |
21 |
Correct |
13 ms |
6904 KB |
Output is correct |
22 |
Correct |
13 ms |
6776 KB |
Output is correct |
23 |
Correct |
13 ms |
6776 KB |
Output is correct |
24 |
Correct |
7 ms |
4216 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
1 ms |
1400 KB |
Output is correct |
28 |
Correct |
1 ms |
760 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
1656 KB |
Output is correct |
3 |
Correct |
3 ms |
1656 KB |
Output is correct |
4 |
Correct |
3 ms |
1656 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
1788 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1784 KB |
Output is correct |
10 |
Correct |
4 ms |
1756 KB |
Output is correct |
11 |
Correct |
3 ms |
1784 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 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 |
10 ms |
5240 KB |
Output is correct |
18 |
Correct |
10 ms |
5244 KB |
Output is correct |
19 |
Correct |
10 ms |
5240 KB |
Output is correct |
20 |
Correct |
8 ms |
4856 KB |
Output is correct |
21 |
Correct |
13 ms |
6904 KB |
Output is correct |
22 |
Correct |
13 ms |
6776 KB |
Output is correct |
23 |
Correct |
13 ms |
6776 KB |
Output is correct |
24 |
Correct |
7 ms |
4216 KB |
Output is correct |
25 |
Correct |
46 ms |
15828 KB |
Output is correct |
26 |
Correct |
39 ms |
15760 KB |
Output is correct |
27 |
Correct |
41 ms |
15784 KB |
Output is correct |
28 |
Correct |
37 ms |
18728 KB |
Output is correct |
29 |
Correct |
68 ms |
27932 KB |
Output is correct |
30 |
Correct |
74 ms |
27652 KB |
Output is correct |
31 |
Correct |
63 ms |
26792 KB |
Output is correct |
32 |
Correct |
63 ms |
26372 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
1 ms |
1400 KB |
Output is correct |
36 |
Correct |
1 ms |
760 KB |
Output is correct |
37 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
1656 KB |
Output is correct |
3 |
Correct |
3 ms |
1656 KB |
Output is correct |
4 |
Correct |
3 ms |
1656 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
1788 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1784 KB |
Output is correct |
10 |
Correct |
4 ms |
1756 KB |
Output is correct |
11 |
Correct |
3 ms |
1784 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 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 |
10 ms |
5240 KB |
Output is correct |
18 |
Correct |
10 ms |
5244 KB |
Output is correct |
19 |
Correct |
10 ms |
5240 KB |
Output is correct |
20 |
Correct |
8 ms |
4856 KB |
Output is correct |
21 |
Correct |
13 ms |
6904 KB |
Output is correct |
22 |
Correct |
13 ms |
6776 KB |
Output is correct |
23 |
Correct |
13 ms |
6776 KB |
Output is correct |
24 |
Correct |
7 ms |
4216 KB |
Output is correct |
25 |
Correct |
46 ms |
15828 KB |
Output is correct |
26 |
Correct |
39 ms |
15760 KB |
Output is correct |
27 |
Correct |
41 ms |
15784 KB |
Output is correct |
28 |
Correct |
37 ms |
18728 KB |
Output is correct |
29 |
Correct |
68 ms |
27932 KB |
Output is correct |
30 |
Correct |
74 ms |
27652 KB |
Output is correct |
31 |
Correct |
63 ms |
26792 KB |
Output is correct |
32 |
Correct |
63 ms |
26372 KB |
Output is correct |
33 |
Correct |
531 ms |
87192 KB |
Output is correct |
34 |
Correct |
612 ms |
87232 KB |
Output is correct |
35 |
Correct |
524 ms |
87172 KB |
Output is correct |
36 |
Correct |
509 ms |
87276 KB |
Output is correct |
37 |
Correct |
813 ms |
99816 KB |
Output is correct |
38 |
Correct |
671 ms |
99720 KB |
Output is correct |
39 |
Correct |
689 ms |
99740 KB |
Output is correct |
40 |
Correct |
636 ms |
95948 KB |
Output is correct |
41 |
Correct |
315 ms |
75192 KB |
Output is correct |
42 |
Correct |
437 ms |
83908 KB |
Output is correct |
43 |
Incorrect |
886 ms |
114260 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
31352 KB |
Output is correct |
2 |
Correct |
32 ms |
26568 KB |
Output is correct |
3 |
Correct |
3 ms |
636 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
28 ms |
21880 KB |
Output is correct |
6 |
Correct |
27 ms |
21496 KB |
Output is correct |
7 |
Correct |
27 ms |
21624 KB |
Output is correct |
8 |
Correct |
25 ms |
20344 KB |
Output is correct |
9 |
Correct |
25 ms |
19832 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 |
2154 ms |
247428 KB |
Output is correct |
3 |
Execution timed out |
5077 ms |
457444 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
548 KB |
Output is correct |
2 |
Correct |
3 ms |
1656 KB |
Output is correct |
3 |
Correct |
3 ms |
1656 KB |
Output is correct |
4 |
Correct |
3 ms |
1656 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
4 ms |
1788 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1784 KB |
Output is correct |
10 |
Correct |
4 ms |
1756 KB |
Output is correct |
11 |
Correct |
3 ms |
1784 KB |
Output is correct |
12 |
Correct |
4 ms |
1784 KB |
Output is correct |
13 |
Correct |
1 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 |
10 ms |
5240 KB |
Output is correct |
18 |
Correct |
10 ms |
5244 KB |
Output is correct |
19 |
Correct |
10 ms |
5240 KB |
Output is correct |
20 |
Correct |
8 ms |
4856 KB |
Output is correct |
21 |
Correct |
13 ms |
6904 KB |
Output is correct |
22 |
Correct |
13 ms |
6776 KB |
Output is correct |
23 |
Correct |
13 ms |
6776 KB |
Output is correct |
24 |
Correct |
7 ms |
4216 KB |
Output is correct |
25 |
Correct |
46 ms |
15828 KB |
Output is correct |
26 |
Correct |
39 ms |
15760 KB |
Output is correct |
27 |
Correct |
41 ms |
15784 KB |
Output is correct |
28 |
Correct |
37 ms |
18728 KB |
Output is correct |
29 |
Correct |
68 ms |
27932 KB |
Output is correct |
30 |
Correct |
74 ms |
27652 KB |
Output is correct |
31 |
Correct |
63 ms |
26792 KB |
Output is correct |
32 |
Correct |
63 ms |
26372 KB |
Output is correct |
33 |
Correct |
531 ms |
87192 KB |
Output is correct |
34 |
Correct |
612 ms |
87232 KB |
Output is correct |
35 |
Correct |
524 ms |
87172 KB |
Output is correct |
36 |
Correct |
509 ms |
87276 KB |
Output is correct |
37 |
Correct |
813 ms |
99816 KB |
Output is correct |
38 |
Correct |
671 ms |
99720 KB |
Output is correct |
39 |
Correct |
689 ms |
99740 KB |
Output is correct |
40 |
Correct |
636 ms |
95948 KB |
Output is correct |
41 |
Correct |
315 ms |
75192 KB |
Output is correct |
42 |
Correct |
437 ms |
83908 KB |
Output is correct |
43 |
Incorrect |
886 ms |
114260 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |