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 <vector>
#include <iostream>
using namespace std;
vector<vector<int> > a,sum,secvl,secvc;
int n,m,i,j,mx;
int solve_n_mic()
{
int ans=0;
if(n<=2) return 0;
for(i=1;i<=m-2;i++)
{
bool bun=(a[1][i]<a[1][i-1]&&a[1][i]<a[0][i]&&a[1][i]<a[2][i]);
mx=a[1][i];
for(j=i;j<=m-2;j++)
{
bun&=(a[1][j]<a[0][j]&&a[1][j]<a[2][j]);
mx=max(mx,a[1][j]);
if(bun&&mx<a[1][i-1]&&mx<a[1][j+1])
ans++;
}
}
return ans;
}
int S(int xl,int yl,int xr,int yr)
{
int ret=sum[xr][yr];
if(xl) ret-=sum[xl-1][yr];
if(yl) ret-=sum[xr][yl-1];
if(xl&&yl) ret+=sum[xl-1][yl-1];
return ret;
}
int solve01()
{
int ans=0;
sum=a;secvl=a;secvc=a;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(i) sum[i][j]+=sum[i-1][j];
if(j) sum[i][j]+=sum[i][j-1];
if(i&&j) sum[i][j]-=sum[i-1][j-1];
secvl[i][j]=secvc[i][j]=0;
}
}
int L,C;
for(i=1;i<n-1;i++)
{
for(j=1;j<m-1;j++)
{
if(a[i][j]==0)
secvl[i][j]=secvl[i-1][j]+1;
if(a[i][j]==0)
secvc[i][j]=secvc[i][j-1]+1;
L=secvl[i][j];C=secvc[i][j];
if(a[i][j]==0&&S(i-L+1,j-C+1,i,j)==0&&S(i-L,j-C,i+1,j+1)==2*(L+C+4)-4)
ans++;
}
}
return ans;
}
long long count_rectangles(vector<vector<int> > att) {
a=att;
n=a.size();m=a[0].size();
int M=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
M=max(M,a[i][j]);
if(n<=3)
return solve_n_mic();
if(M==1)
return solve01();
return 1;
}
Compilation message (stderr)
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:72:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(M==1)
^~
rect.cpp:74:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return 1;
^~~~~~
# | 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... |