Submission #348049

#TimeUsernameProblemLanguageResultExecution timeMemory
348049juggernautRectangles (IOI19_rect)C++14
50 / 100
3609 ms98540 KiB
#include"rect.h" #include<bits/stdc++.h> #ifdef EVAL #else #include"grader.cpp" #endif using namespace std; int b[2505][2505],n,m; vector<vector<int>>a; bool check(int r1,int c1,int r2,int c2){ for(int i=r1;i<=r2;i++) for(int j=c1;j<=c2;j++) if(a[i][j]>=min(min(a[i][c1-1],a[i][c2+1]),min(a[r1-1][j],a[r2+1][j])))return 0; return 1; } int get(int x,int y,int x2,int y2){ int sum=b[x2][y2]; if(x&&y)sum+=b[x-1][y-1]; if(x)sum-=b[x-1][y2]; if(y)sum-=b[x2][y-1]; return sum; } long long count_rectangles(vector<vector<int>>a){ n=a.size(),m=a[0].size(); ::a=a; long long res=0; if((n<=200&&m<=200)||(n<=3)){ for(int i=1;i<n-1;i++) for(int j=1;j<m-1;j++) for(int I=i;I<n-1;I++) for(int J=j;J<m-1;J++)res+=check(i,j,I,J); }else{ for(int i=0;i<n;i++) for(int j=0;j<m;j++){ b[i][j]=a[i][j]; if(i&&j)b[i][j]-=b[i-1][j-1]; if(i)b[i][j]+=b[i-1][j]; if(j)b[i][j]+=b[i][j-1]; } for(int i=1;i+1<n;i++) for(int j=1;j+1<m;j++) if(!a[i][j]&&a[i][j-1]&&a[i-1][j]){ int x=i; while(x+1<n&&!a[x+1][j])x++; int y=j; while(y+1<m&&!a[i][y+1])y++; if(get(i,j,x,y)==0&&get(i-1,j,i-1,y)==y-j+1&&get(x+1,j,x+1,y)==y-j+1&&get(i,j-1,x,j-1)==x-i+1&&get(i,y+1,x,y+1)==x-i+1)res++; } } return res; }
#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...