# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
536438 |
2022-03-13T10:14:28 Z |
zggf |
Rectangles (IOI19_rect) |
C++14 |
|
2 ms |
696 KB |
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
long long count_rectangles(vector<vector<int>> tab) {
int n = tab.size();
int m = tab[0].size();
vector<vector<int>> lft(n, vector<int>(m));
vector<vector<int>> up(n, vector<int>(m));
vector<vector<vector<int>>> pos;
pos.resize(n, vector<vector<int>>(m));
for(int i = 0; i < n; i++){
lft[i][0] = -1;
for(int j = 1; j < m; j++){
int pt = j-1;
while(pt!=-1&&tab[i][pt]<tab[i][j]){
pt = lft[i][pt];
pos[i][j-1].push_back(pt);
}
if(pos[i][j-1].size()&&pos[i][j-1].back()==-1){
pos[i][j-1].pop_back();
}
lft[i][j] = pt;
if(tab[i][j]<=tab[i][j-1]){
pos[i][j-1].resize(0);
}
}
}
vector<int> time(m+10);
int wyn = 0;
int cur = 10;
for(int i = 0; i < m-1; i++){
for(int j = 0; j < n; j++){
cur+=2;
int pt = j-1;
vector<int> pos2;
while(pt!=-1&&tab[pt][i]<tab[j][i]){
pos2.push_back(pt);
pt = up[pt][i];
}
//cout<<j<<" "<<i<<" "<<pos2.size()<<'\n';
if(pos2.size()){
//cout<<pos2[0]<<" "<<pos[pos2[0]][i].size()<<'\n';
for(auto it:pos[pos2[0]][i]){
if(pos2[0]!=0){
time[it] = cur;
wyn++;
//cout<<j<<" "<<i<<" "<<pos2[0]<<" "<<it<<'\n';
}
}
}
for(int k = 1; k < (int)pos2.size(); k++){
for(auto it:pos[pos2[k]][i]){
if(time[it]==cur){
if(pos2[k]!=0){
time[it]++;
wyn++;
//cout<<j<<" "<<i<<" "<<pos2[k]<<" "<<it<<'\n';
}
}
}
cur++;
}
if(pos2.size()){
pos[j][i].resize(0);
for(auto it:pos[pos2.back()][i]){
if(time[it]==cur){
pos[j][i].push_back(it);
}
}
}
up[j][i] = pt;
}
}
/*
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout<<i<<" "<<j<<": ";
for(auto it:pos[i][j]) cout<<it<<" ";
cout<<'\n';
}
}
*/
return wyn;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
564 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Incorrect |
2 ms |
696 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |