# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
928470 |
2024-02-16T12:59:55 Z |
knon0501 |
Rectangles (IOI19_rect) |
C++14 |
|
208 ms |
192232 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> b[2505][2505];
vector<vector<int>> aa;
int f(int i,int j,int x,int y){
int cnt1 = 0;
int cnt2 = 0;
for(int k=i ; k<=j ; k++){
if(aa[x][k]<aa[y][k])
cnt1++;
if(aa[x][k]>aa[y][k])
cnt2++;
}
if(cnt1==j-i+1)return 1;
if(cnt2==j-i+1)return -1;
return 0;
}
long long count_rectangles(std::vector<std::vector<int> > a) {
aa=a;
int n = a.size();
int m = a[0].size();
for(int i=1 ; i<n-1 ; i++){
stack<int> S;
for(int j=0 ; j<m ; j++){
bool flag = true;
while(!S.empty() && a[i][S.top()] <= a[i][j]){
int x = S.top();
if(x +1 <j && flag)
b[x+1][j-1].push_back(i);
if(a[i][S.top()]==a[i][j])flag=false;
S.pop();
}
if(!S.empty() && flag){
int x = S.top();
if(x+1<j)
b[x+1][j-1].push_back(i);
}
S.push(j);
}
}
long long ans = 0;
for(int i=1 ; i<= n ; i++){
for(int j=i ; j<=n ; j++){
vector<vector<int>> c;
int prv=-1;
for(int x: b[i][j]){
// cout<<i<<" "<<j<<" "<<x<<endl;
if(prv+1<x)
c.push_back({x});
else
c.back().push_back(x);
prv=x;
}
for(auto d: c){
stack<int> S;
d.push_back(d.back()+1);
d.push_back(d[0]-1);
sort(d.begin(),d.end());
for(auto x: d){
bool flag = true;
while(!S.empty() && f(i,j,S.top(),x)>=0){
int k = S.top(); S.pop();
if(k +1 <x && flag){
ans++;
}
if(f(i,j,k,x)==0)
flag=false;
}
if(!S.empty() && S.top()+1<x && flag)
ans++;
S.push(x);
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147804 KB |
Output is correct |
3 |
Correct |
33 ms |
147800 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
34 ms |
147804 KB |
Output is correct |
7 |
Incorrect |
36 ms |
147532 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147804 KB |
Output is correct |
3 |
Correct |
33 ms |
147800 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
34 ms |
147804 KB |
Output is correct |
7 |
Incorrect |
36 ms |
147532 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147804 KB |
Output is correct |
3 |
Correct |
33 ms |
147800 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
34 ms |
147804 KB |
Output is correct |
7 |
Incorrect |
36 ms |
147532 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147804 KB |
Output is correct |
3 |
Correct |
33 ms |
147800 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
34 ms |
147804 KB |
Output is correct |
7 |
Incorrect |
36 ms |
147532 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
94 ms |
147852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
147544 KB |
Output is correct |
2 |
Incorrect |
208 ms |
192232 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
147540 KB |
Output is correct |
2 |
Correct |
34 ms |
147804 KB |
Output is correct |
3 |
Correct |
33 ms |
147800 KB |
Output is correct |
4 |
Correct |
33 ms |
147792 KB |
Output is correct |
5 |
Correct |
33 ms |
147536 KB |
Output is correct |
6 |
Correct |
34 ms |
147804 KB |
Output is correct |
7 |
Incorrect |
36 ms |
147532 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |