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>
#ifdef EVAL
#else
#include"grader.cpp"
#endif
using namespace std;
int b[2505][2505];
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){
int n=a.size(),m=a[0].size();
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];
}
long long res=0;
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 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... |