# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
836423 |
2023-08-24T11:03:32 Z |
Antekb |
Rectangles (IOI19_rect) |
C++17 |
|
805 ms |
1048576 KB |
#include<bits/stdc++.h>
#include "rect.h"
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pii>;
using ll = long long;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
cerr<<h;
if(sizeof...(t))cerr<<", ";
debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
const int N=2505;
ll count_rectangles(std::vector<std::vector<int> > tab) {
int n=tab.size(), m=tab[0].size();
vector<vector<bitset<N> > > par(n, vector<bitset<N> >(m));
for(int i=1; i<m-1; i++){
vi V={0};
for(int j=1; j<n; j++){
while(V.size() && tab[j][i]>tab[V.back()][i]){
if(V.back()!=j-1)par[j][i][V.back()]=1;
V.pp();
}
if(V.size() && V.back()!=j-1)par[j][i][V.back()]=1;
if(V.size() && tab[V.back()][i]==tab[j][i])V.pp();
V.pb(j);
}
}
/*for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
//deb(i, j);
for(int k:par[i][j]){
//deb(k);
}
}
}*/
vector<pii> prv;
vi dp2;
ll ans=0;
for(int r=1; r<n-1; r++){
vector<pii> akt;
vi dp;
vi V={m-1};
for(int j=m-2; j>=0; j--){
while(V.size() && tab[r][j]>tab[r][V.back()]){
if(V.back()!=j+1){
akt.eb(j, V.back());
}
V.pp();
}
if(V.size() && V.back()!=j+1){
akt.eb(j, V.back());
}
if(V.size() && tab[r][V.back()]==tab[r][j])V.pp();
V.pb(j);
}
dp.resize(akt.size(), 1);
int wsk=0;
for(int i=0; i<akt.size(); i++){
while(wsk<prv.size() && (akt[i].st<prv[wsk].st
|| (akt[i].st==prv[wsk].st && akt[i].nd>prv[wsk].nd)))wsk++;
if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
}
vi wsk2(m);
vector<int> S;
vector<bitset<N> > b(akt.size());
for(int i=0; i<akt.size(); i++){
//deb(r, i, akt[i].st, akt[i].nd, dp[i]);
for(int k=r-1; k>=r-dp[i]; k--)b[i][k]=1;
int pocz=akt[i].st+1;
/*while(S.size()){
int a=S.back();
if(akt[a].st>=akt[i].nd)break;
S.pp();
for(;pocz<=akt[a].st;pocz++){
b[i]&=par[r+1][pocz];
}
b[i]&=b[a];
pocz=akt[a].nd;
}*/
S.pb(i);
for(int j=0; j<i; j++){
if(akt[i].nd>=akt[j].nd){
b[i]&=b[j];
}
}
for(;pocz<akt[i].nd;pocz++){
b[i]&=par[r+1][pocz];
}
ans+=b[i].count();
/*for(int k=r-1; k>=r-dp[i]; k--){
if(b[i][k]){
//deb(r, akt[i].st, akt[i].nd, k);
ans++;
}
}*/
}
prv=akt;
dp2=dp;
}
return ans;
}
Compilation message
rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:74:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i=0; i<akt.size(); i++){
| ~^~~~~~~~~~~
rect.cpp:75:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | while(wsk<prv.size() && (akt[i].st<prv[wsk].st
| ~~~^~~~~~~~~~~
rect.cpp:77:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | if(wsk<prv.size() && akt[i]==prv[wsk])dp[i]+=dp2[wsk];
| ~~~^~~~~~~~~~~
rect.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i=0; i<akt.size(); i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Incorrect |
1 ms |
596 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 |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Incorrect |
1 ms |
596 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 |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Incorrect |
1 ms |
596 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 |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
3564 KB |
Output is correct |
2 |
Correct |
117 ms |
3052 KB |
Output is correct |
3 |
Correct |
2 ms |
3484 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
3524 KB |
Output is correct |
6 |
Correct |
5 ms |
3508 KB |
Output is correct |
7 |
Correct |
4 ms |
3524 KB |
Output is correct |
8 |
Correct |
5 ms |
3524 KB |
Output is correct |
9 |
Correct |
4 ms |
3412 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
805 ms |
923660 KB |
Output is correct |
3 |
Runtime error |
427 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |