# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
155805 |
2019-09-30T15:58:13 Z |
vanic |
Rectangles (IOI19_rect) |
C++14 |
|
5000 ms |
1023008 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=2521;
int n, m;
int l[maxn][maxn];
//vector < int > r[maxn][maxn], c[maxn][maxn];
unordered_map < short, short > r[maxn][maxn], c[maxn][maxn];
short rind[maxn][maxn], cind[maxn][maxn];
pair < int, int > red[maxn][maxn], stup[maxn][maxn];
//int bio2[maxn][maxn], bio3[maxn][maxn];
vector < array < short, 4 > > bio;
void upd1(int x){
stack < pair < int, short > > 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(r[red[x][i].first][red[x][i].second].find(x)==r[red[x][i].first][red[x][i].second].end()){
// bio2[red[x][i].first][red[x][i].second]=x+1;
r[red[x][i].first][red[x][i].second][x]=r[red[x][i].first][red[x][i].second][rind[red[x][i].first][red[x][i].second]]+1;
rind[red[x][i].first][red[x][i].second]=x;
}
q.push(make_pair(l[x][i], i));
}
}
void upd2(int x){
stack < pair < int, short > > 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(c[stup[i][x].first][stup[i][x].second].find(x)==c[stup[i][x].first][stup[i][x].second].end()){
// bio3[stup[i][x].first][stup[i][x].second]=x+1;
c[stup[i][x].first][stup[i][x].second][x]=c[stup[i][x].first][stup[i][x].second][cind[stup[i][x].first][stup[i][x].second]]+1;
cind[stup[i][x].first][stup[i][x].second]=x;
}
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[r1][r2].find(c2)!=r[r1][r2].end() && r[r1][r2].find(c1)!=r[r1][r2].end()
&& c[c1][c2].find(r2)!=c[c1][c2].end() && c[c1][c2].find(r1)!=c[c1][c2].end()
&& r[r1][r2][c2]-r[r1][r2][c1]==c2-c1 && c[c1][c2][r2]-c[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", bio.size());
return 0;
}*/
Compilation message
rect.cpp: In function 'void provjeri(int, int)':
rect.cpp:112:33: warning: narrowing conversion of 'r1' from 'int' to 'short int' inside { } [-Wnarrowing]
bio.push_back({r1, r2, c1, c2});
^
rect.cpp:112:33: warning: narrowing conversion of 'r2' from 'int' to 'short int' inside { } [-Wnarrowing]
rect.cpp:112:33: warning: narrowing conversion of 'c1' from 'int' to 'short int' inside { } [-Wnarrowing]
rect.cpp:112:33: warning: narrowing conversion of 'c2' from 'int' to 'short int' inside { } [-Wnarrowing]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
778 ms |
696952 KB |
Output is correct |
2 |
Correct |
828 ms |
697548 KB |
Output is correct |
3 |
Correct |
830 ms |
697636 KB |
Output is correct |
4 |
Correct |
726 ms |
697564 KB |
Output is correct |
5 |
Correct |
749 ms |
697336 KB |
Output is correct |
6 |
Correct |
751 ms |
697804 KB |
Output is correct |
7 |
Correct |
834 ms |
697336 KB |
Output is correct |
8 |
Correct |
692 ms |
697208 KB |
Output is correct |
9 |
Correct |
705 ms |
697484 KB |
Output is correct |
10 |
Correct |
699 ms |
697620 KB |
Output is correct |
11 |
Correct |
729 ms |
697528 KB |
Output is correct |
12 |
Correct |
721 ms |
697456 KB |
Output is correct |
13 |
Correct |
699 ms |
696824 KB |
Output is correct |
14 |
Correct |
699 ms |
696940 KB |
Output is correct |
15 |
Correct |
695 ms |
696952 KB |
Output is correct |
16 |
Correct |
698 ms |
696824 KB |
Output is correct |
17 |
Correct |
805 ms |
696912 KB |
Output is correct |
18 |
Correct |
738 ms |
696784 KB |
Output is correct |
19 |
Correct |
785 ms |
697464 KB |
Output is correct |
20 |
Correct |
739 ms |
697192 KB |
Output is correct |
21 |
Correct |
737 ms |
696992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
778 ms |
696952 KB |
Output is correct |
2 |
Correct |
828 ms |
697548 KB |
Output is correct |
3 |
Correct |
830 ms |
697636 KB |
Output is correct |
4 |
Correct |
726 ms |
697564 KB |
Output is correct |
5 |
Correct |
749 ms |
697336 KB |
Output is correct |
6 |
Correct |
751 ms |
697804 KB |
Output is correct |
7 |
Correct |
834 ms |
697336 KB |
Output is correct |
8 |
Correct |
692 ms |
697208 KB |
Output is correct |
9 |
Correct |
705 ms |
697484 KB |
Output is correct |
10 |
Correct |
699 ms |
697620 KB |
Output is correct |
11 |
Correct |
729 ms |
697528 KB |
Output is correct |
12 |
Correct |
721 ms |
697456 KB |
Output is correct |
13 |
Correct |
699 ms |
696824 KB |
Output is correct |
14 |
Correct |
699 ms |
696940 KB |
Output is correct |
15 |
Correct |
695 ms |
696952 KB |
Output is correct |
16 |
Correct |
698 ms |
696824 KB |
Output is correct |
17 |
Correct |
714 ms |
699448 KB |
Output is correct |
18 |
Correct |
712 ms |
699488 KB |
Output is correct |
19 |
Correct |
780 ms |
699520 KB |
Output is correct |
20 |
Correct |
707 ms |
698900 KB |
Output is correct |
21 |
Correct |
732 ms |
699372 KB |
Output is correct |
22 |
Correct |
753 ms |
699396 KB |
Output is correct |
23 |
Correct |
743 ms |
699372 KB |
Output is correct |
24 |
Correct |
703 ms |
698756 KB |
Output is correct |
25 |
Correct |
805 ms |
696912 KB |
Output is correct |
26 |
Correct |
738 ms |
696784 KB |
Output is correct |
27 |
Correct |
785 ms |
697464 KB |
Output is correct |
28 |
Correct |
739 ms |
697192 KB |
Output is correct |
29 |
Correct |
737 ms |
696992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
778 ms |
696952 KB |
Output is correct |
2 |
Correct |
828 ms |
697548 KB |
Output is correct |
3 |
Correct |
830 ms |
697636 KB |
Output is correct |
4 |
Correct |
726 ms |
697564 KB |
Output is correct |
5 |
Correct |
749 ms |
697336 KB |
Output is correct |
6 |
Correct |
751 ms |
697804 KB |
Output is correct |
7 |
Correct |
834 ms |
697336 KB |
Output is correct |
8 |
Correct |
692 ms |
697208 KB |
Output is correct |
9 |
Correct |
705 ms |
697484 KB |
Output is correct |
10 |
Correct |
699 ms |
697620 KB |
Output is correct |
11 |
Correct |
729 ms |
697528 KB |
Output is correct |
12 |
Correct |
721 ms |
697456 KB |
Output is correct |
13 |
Correct |
699 ms |
696824 KB |
Output is correct |
14 |
Correct |
699 ms |
696940 KB |
Output is correct |
15 |
Correct |
695 ms |
696952 KB |
Output is correct |
16 |
Correct |
698 ms |
696824 KB |
Output is correct |
17 |
Correct |
714 ms |
699448 KB |
Output is correct |
18 |
Correct |
712 ms |
699488 KB |
Output is correct |
19 |
Correct |
780 ms |
699520 KB |
Output is correct |
20 |
Correct |
707 ms |
698900 KB |
Output is correct |
21 |
Correct |
732 ms |
699372 KB |
Output is correct |
22 |
Correct |
753 ms |
699396 KB |
Output is correct |
23 |
Correct |
743 ms |
699372 KB |
Output is correct |
24 |
Correct |
703 ms |
698756 KB |
Output is correct |
25 |
Correct |
763 ms |
706236 KB |
Output is correct |
26 |
Correct |
741 ms |
706244 KB |
Output is correct |
27 |
Correct |
799 ms |
706244 KB |
Output is correct |
28 |
Correct |
737 ms |
703660 KB |
Output is correct |
29 |
Correct |
831 ms |
706332 KB |
Output is correct |
30 |
Correct |
769 ms |
706424 KB |
Output is correct |
31 |
Correct |
744 ms |
706088 KB |
Output is correct |
32 |
Correct |
747 ms |
705800 KB |
Output is correct |
33 |
Correct |
805 ms |
696912 KB |
Output is correct |
34 |
Correct |
738 ms |
696784 KB |
Output is correct |
35 |
Correct |
785 ms |
697464 KB |
Output is correct |
36 |
Correct |
739 ms |
697192 KB |
Output is correct |
37 |
Correct |
737 ms |
696992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
778 ms |
696952 KB |
Output is correct |
2 |
Correct |
828 ms |
697548 KB |
Output is correct |
3 |
Correct |
830 ms |
697636 KB |
Output is correct |
4 |
Correct |
726 ms |
697564 KB |
Output is correct |
5 |
Correct |
749 ms |
697336 KB |
Output is correct |
6 |
Correct |
751 ms |
697804 KB |
Output is correct |
7 |
Correct |
834 ms |
697336 KB |
Output is correct |
8 |
Correct |
692 ms |
697208 KB |
Output is correct |
9 |
Correct |
705 ms |
697484 KB |
Output is correct |
10 |
Correct |
699 ms |
697620 KB |
Output is correct |
11 |
Correct |
729 ms |
697528 KB |
Output is correct |
12 |
Correct |
721 ms |
697456 KB |
Output is correct |
13 |
Correct |
699 ms |
696824 KB |
Output is correct |
14 |
Correct |
699 ms |
696940 KB |
Output is correct |
15 |
Correct |
695 ms |
696952 KB |
Output is correct |
16 |
Correct |
698 ms |
696824 KB |
Output is correct |
17 |
Correct |
714 ms |
699448 KB |
Output is correct |
18 |
Correct |
712 ms |
699488 KB |
Output is correct |
19 |
Correct |
780 ms |
699520 KB |
Output is correct |
20 |
Correct |
707 ms |
698900 KB |
Output is correct |
21 |
Correct |
732 ms |
699372 KB |
Output is correct |
22 |
Correct |
753 ms |
699396 KB |
Output is correct |
23 |
Correct |
743 ms |
699372 KB |
Output is correct |
24 |
Correct |
703 ms |
698756 KB |
Output is correct |
25 |
Correct |
763 ms |
706236 KB |
Output is correct |
26 |
Correct |
741 ms |
706244 KB |
Output is correct |
27 |
Correct |
799 ms |
706244 KB |
Output is correct |
28 |
Correct |
737 ms |
703660 KB |
Output is correct |
29 |
Correct |
831 ms |
706332 KB |
Output is correct |
30 |
Correct |
769 ms |
706424 KB |
Output is correct |
31 |
Correct |
744 ms |
706088 KB |
Output is correct |
32 |
Correct |
747 ms |
705800 KB |
Output is correct |
33 |
Correct |
1351 ms |
791936 KB |
Output is correct |
34 |
Correct |
1206 ms |
792020 KB |
Output is correct |
35 |
Correct |
1153 ms |
792056 KB |
Output is correct |
36 |
Correct |
1108 ms |
791968 KB |
Output is correct |
37 |
Correct |
1427 ms |
767216 KB |
Output is correct |
38 |
Correct |
1338 ms |
767204 KB |
Output is correct |
39 |
Correct |
1325 ms |
767084 KB |
Output is correct |
40 |
Correct |
1282 ms |
763336 KB |
Output is correct |
41 |
Correct |
1000 ms |
736388 KB |
Output is correct |
42 |
Correct |
1368 ms |
742140 KB |
Output is correct |
43 |
Correct |
1738 ms |
773116 KB |
Output is correct |
44 |
Correct |
1630 ms |
774232 KB |
Output is correct |
45 |
Correct |
1112 ms |
741672 KB |
Output is correct |
46 |
Correct |
1129 ms |
737248 KB |
Output is correct |
47 |
Correct |
1507 ms |
767796 KB |
Output is correct |
48 |
Correct |
1522 ms |
768280 KB |
Output is correct |
49 |
Correct |
805 ms |
696912 KB |
Output is correct |
50 |
Correct |
738 ms |
696784 KB |
Output is correct |
51 |
Correct |
785 ms |
697464 KB |
Output is correct |
52 |
Correct |
739 ms |
697192 KB |
Output is correct |
53 |
Correct |
737 ms |
696992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
765 ms |
707900 KB |
Output is correct |
2 |
Correct |
787 ms |
706340 KB |
Output is correct |
3 |
Correct |
710 ms |
697332 KB |
Output is correct |
4 |
Correct |
769 ms |
696904 KB |
Output is correct |
5 |
Correct |
764 ms |
706908 KB |
Output is correct |
6 |
Correct |
711 ms |
706680 KB |
Output is correct |
7 |
Correct |
715 ms |
706848 KB |
Output is correct |
8 |
Correct |
732 ms |
706168 KB |
Output is correct |
9 |
Correct |
745 ms |
705924 KB |
Output is correct |
10 |
Correct |
795 ms |
702504 KB |
Output is correct |
11 |
Correct |
765 ms |
705116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
750 ms |
697020 KB |
Output is correct |
2 |
Correct |
2817 ms |
858948 KB |
Output is correct |
3 |
Execution timed out |
5102 ms |
1023008 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
778 ms |
696952 KB |
Output is correct |
2 |
Correct |
828 ms |
697548 KB |
Output is correct |
3 |
Correct |
830 ms |
697636 KB |
Output is correct |
4 |
Correct |
726 ms |
697564 KB |
Output is correct |
5 |
Correct |
749 ms |
697336 KB |
Output is correct |
6 |
Correct |
751 ms |
697804 KB |
Output is correct |
7 |
Correct |
834 ms |
697336 KB |
Output is correct |
8 |
Correct |
692 ms |
697208 KB |
Output is correct |
9 |
Correct |
705 ms |
697484 KB |
Output is correct |
10 |
Correct |
699 ms |
697620 KB |
Output is correct |
11 |
Correct |
729 ms |
697528 KB |
Output is correct |
12 |
Correct |
721 ms |
697456 KB |
Output is correct |
13 |
Correct |
699 ms |
696824 KB |
Output is correct |
14 |
Correct |
699 ms |
696940 KB |
Output is correct |
15 |
Correct |
695 ms |
696952 KB |
Output is correct |
16 |
Correct |
698 ms |
696824 KB |
Output is correct |
17 |
Correct |
714 ms |
699448 KB |
Output is correct |
18 |
Correct |
712 ms |
699488 KB |
Output is correct |
19 |
Correct |
780 ms |
699520 KB |
Output is correct |
20 |
Correct |
707 ms |
698900 KB |
Output is correct |
21 |
Correct |
732 ms |
699372 KB |
Output is correct |
22 |
Correct |
753 ms |
699396 KB |
Output is correct |
23 |
Correct |
743 ms |
699372 KB |
Output is correct |
24 |
Correct |
703 ms |
698756 KB |
Output is correct |
25 |
Correct |
763 ms |
706236 KB |
Output is correct |
26 |
Correct |
741 ms |
706244 KB |
Output is correct |
27 |
Correct |
799 ms |
706244 KB |
Output is correct |
28 |
Correct |
737 ms |
703660 KB |
Output is correct |
29 |
Correct |
831 ms |
706332 KB |
Output is correct |
30 |
Correct |
769 ms |
706424 KB |
Output is correct |
31 |
Correct |
744 ms |
706088 KB |
Output is correct |
32 |
Correct |
747 ms |
705800 KB |
Output is correct |
33 |
Correct |
1351 ms |
791936 KB |
Output is correct |
34 |
Correct |
1206 ms |
792020 KB |
Output is correct |
35 |
Correct |
1153 ms |
792056 KB |
Output is correct |
36 |
Correct |
1108 ms |
791968 KB |
Output is correct |
37 |
Correct |
1427 ms |
767216 KB |
Output is correct |
38 |
Correct |
1338 ms |
767204 KB |
Output is correct |
39 |
Correct |
1325 ms |
767084 KB |
Output is correct |
40 |
Correct |
1282 ms |
763336 KB |
Output is correct |
41 |
Correct |
1000 ms |
736388 KB |
Output is correct |
42 |
Correct |
1368 ms |
742140 KB |
Output is correct |
43 |
Correct |
1738 ms |
773116 KB |
Output is correct |
44 |
Correct |
1630 ms |
774232 KB |
Output is correct |
45 |
Correct |
1112 ms |
741672 KB |
Output is correct |
46 |
Correct |
1129 ms |
737248 KB |
Output is correct |
47 |
Correct |
1507 ms |
767796 KB |
Output is correct |
48 |
Correct |
1522 ms |
768280 KB |
Output is correct |
49 |
Correct |
765 ms |
707900 KB |
Output is correct |
50 |
Correct |
787 ms |
706340 KB |
Output is correct |
51 |
Correct |
710 ms |
697332 KB |
Output is correct |
52 |
Correct |
769 ms |
696904 KB |
Output is correct |
53 |
Correct |
764 ms |
706908 KB |
Output is correct |
54 |
Correct |
711 ms |
706680 KB |
Output is correct |
55 |
Correct |
715 ms |
706848 KB |
Output is correct |
56 |
Correct |
732 ms |
706168 KB |
Output is correct |
57 |
Correct |
745 ms |
705924 KB |
Output is correct |
58 |
Correct |
795 ms |
702504 KB |
Output is correct |
59 |
Correct |
765 ms |
705116 KB |
Output is correct |
60 |
Correct |
750 ms |
697020 KB |
Output is correct |
61 |
Correct |
2817 ms |
858948 KB |
Output is correct |
62 |
Execution timed out |
5102 ms |
1023008 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |