제출 #618756

#제출 시각아이디문제언어결과실행 시간메모리
618756chirathnirodhaRectangles (IOI19_rect)C++17
50 / 100
5083 ms67716 KiB
#include "rect.h" #include<bits/stdc++.h> using namespace std; #define P push #define MP make_pair #define F first #define S second typedef long long ll; long long count_rectangles(vector<vector<int> > a) { int n=a.size(); int m=a[0].size(); int maxi=-1; for(int i=0;i<n;i++)for(int j=0;j<m;j++)maxi=max(maxi,a[i][j]); ll ans=0; if(maxi<2){ bool flood[n][m];memset(flood,false,sizeof(flood)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(flood[i][j] || a[i][j]!=0)continue; flood[i][j]=true; queue<pair<int,int> > q;q.P(MP(i,j)); int up,down,left,right; up=left=3000; down=right=-1; int co=0; while(!q.empty()){ int c=q.front().F,d=q.front().S;q.pop(); up=min(up,c);down=max(down,c); left=min(left,d);right=max(right,d); co++; if(d<m-1 && a[c][d+1]==0 && !flood[c][d+1]){ flood[c][d+1]=true; q.P(MP(c,d+1)); } if(d>0 && a[c][d-1]==0 && !flood[c][d-1]){ flood[c][d-1]=true; q.P(MP(c,d-1)); } if(c<n-1 && a[c+1][d]==0 && !flood[c+1][d]){ flood[c+1][d]=true; q.P(MP(c+1,d)); } if(c>0 && a[c-1][d]==0 && !flood[c-1][d]){ flood[c-1][d]=true; q.P(MP(c-1,d)); } } if(up==0 || down==n-1 || left==0 || right==m-1)continue; if(co==(down-up+1)*(right-left+1))ans++; } } return ans; } for(int i=0;i<n;i++){ int colmax[m];memset(colmax,-1,sizeof(colmax)); bool colvalid[m];memset(colvalid,false,sizeof(colvalid)); for(int j=i+2;j<n;j++){ for(int k=0;k<m;k++){ colmax[k]=max(colmax[k],a[j-1][k]); if(colmax[k]>=a[i][k] || colmax[k]>=a[j][k])colvalid[k]=false; else colvalid[k]=true; } for(int k=0;k<m;k++){ int rowmax[n];memset(rowmax,-1,sizeof(rowmax)); for(int l=k+2;l<m;l++){ if(colvalid[l-1]==false)break; bool ok=true; for(int p=i+1;p<=j-1;p++){ rowmax[p]=max(rowmax[p],a[p][l-1]); if(rowmax[p]>=a[p][k] || rowmax[p]>=a[p][l])ok=false; } if(ok)ans++; } } } } return ans; }
#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...