Submission #422927

#TimeUsernameProblemLanguageResultExecution timeMemory
422927oleh1421Rectangles (IOI19_rect)C++17
59 / 100
3083 ms146532 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]; int A[N][N]; int s(int x1,int y1,int x2,int y2){ x1--; y1--; return A[x2][y2]-A[x1][y2]-A[x2][y1]+A[x1][y1]; } int d[N][N],rr[N][N]; ll count_rectangles(vector<vector<int> > vv) { int Mx=0; 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]; A[i][j]=a[i][j]+A[i][j-1]; Mx=max(Mx,a[i][j]); } for (int j=1;j<=m;j++) A[i][j]+=A[i-1][j]; } for (int i=1;i<=n;i++){ rr[i][m+1]=m+1; for (int j=m;j>=1;j--){ if (a[i][j]) rr[i][j]=j; else rr[i][j]=rr[i][j+1]; } } for (int i=1;i<=m;i++){ d[n+1][i]=n+1; for (int j=n;j>=1;j--){ if (a[j][i]) d[j][i]=j; else d[j][i]=d[j+1][i]; } } // Mx=2; if (Mx<=1){ ll res=0ll; for (int i=1;i<=n-2;i++){ for (int j=1;j<=m-2;j++){ if (a[i+1][j+1]) continue; int x=d[i+1][j+1]; int y=rr[i+1][j+1]; if (s(i+1,j,x-1,j)==x-i-1 && s(i,j+1,i,y-1)==y-j-1 && s(x,j+1,x,y-1)==y-j-1 && s(i+1,y,x-1,y)==x-i-1 && s(i+1,j+1,x-1,y-1)==0) { res++; } } } return res; } 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++; // } } for (int t=1;t<=m;t++){ if (t-2<x[t]) continue; if (y[x[t]]>t) res++; } } } // x[k]==t return res; } /** 10 10 1 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 **/

Compilation message (stderr)

rect.cpp: In function 'll count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:96:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |             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...