Submission #422893

#TimeUsernameProblemLanguageResultExecution timeMemory
422893oleh1421Rectangles (IOI19_rect)C++17
59 / 100
5091 ms59036 KiB
//#include "grader.cpp" #include "rect.h" #include<bits/stdc++.h> typedef long long ll; using namespace std; int n,m; const int N=2500; int a[N][N],l[N][N],r[N][N]; int mx[N]; int L[N],R[N]; int x[N],y[N]; ll count_rectangles(vector<vector<int> > vv) { n=vv.size(),m=vv[0].size(); for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ a[i][j]=vv[i-1][j-1]; } } for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ l[i][j]=0; for (int t=j-1;t>=1;t=l[i][t]){ if (a[i][t]>=a[i][j]){ l[i][j]=t; break; } } } for (int j=m;j>=1;j--){ r[i][j]=m+1; for (int t=j+1;t<=m;t=r[i][t]){ if (a[i][t]>=a[i][j]){ r[i][j]=t; break; } } } } ll res=0ll; for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++) mx[j]=0,L[j]=1,R[j]=m; for (int j=i+2;j<=n;j++){ for (int t=1;t<=m;t++) { mx[t]=max(mx[t],a[j-1][t]); L[t]=max(L[t],l[j-1][t]); R[t]=min(R[t],r[j-1][t]); } vector<int>bad; bad.push_back(0); for (int t=1;t<=m;t++){ if (mx[t]>=min(a[i][t],a[j][t])) bad.push_back(t); } bad.push_back(m+1); for (int t=1;t<bad.size();t++){ for (int k=bad[t-1];k<bad[t];k++){ y[k]=min(R[k],bad[t]); } for (int k=bad[t-1]+1;k<=bad[t];k++){ x[k]=max(L[k],bad[t-1]); } } for (int t=1;t<=m;t++){ if (t+2>y[t]) continue; if (x[y[t]]<=t) res++; for (int k=t+2;k<y[t];k++){ if (t>=x[k]) res++; } } } } return res; } /** 6 5 4 8 7 5 6 7 4 10 3 5 9 7 20 14 2 9 14 7 3 6 5 7 5 2 7 4 5 13 5 6 **/

Compilation message (stderr)

rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for (int t=1;t<bad.size();t++){
      |                          ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...