This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |