이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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)+(1-a[i-L][j-C])+(1-a[i-L][j+1])+(1-a[i+1][j-C])+(1-a[i+1][j+1])==2*(L+C+4)-4)
ans++;
}
}
return ans;
}
int v[105][105],l[105][105][105],c[105][105][105];
int brut()
{
for(int i=1;i<=n-2;i++)
{
for(int j=1;j<=m-2;j++)
{
mx=a[i][j];
for(int k=j;k<=m-2;k++)
{
mx=max(mx,a[i][k]);
l[i][j][k]=((a[i][j-1]>mx&&a[i][k+1]>mx));
if(l[i][j][k])
l[i][j][k]+=l[i-1][j][k];
}
}
}
for(int i=1;i<=m-2;i++)
{
for(int j=1;j<=n-2;j++)
{
mx=a[j][i];
for(int k=j;k<=n-2;k++)
{
mx=max(mx,a[k][i]);
c[i][j][k]=((a[j-1][i]>mx&&a[k+1][i]>mx));
if(c[i][j][k])
c[i][j][k]+=c[i-1][j][k];
}
}
}
int ans=0,l1,l2,c1,c2;
for(l1=1;l1<=n-2;l1++)
for(l2=l1;l2<=n-2;l2++)
for(c1=1;c1<=m-2;c1++)
for(c2=c1;c2<=m-2;c2++)
ans+=((l2-l[l2][c1][c2]<l1)&&(c2-c[c2][l1][l2]<c1));
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 brut();
}
컴파일 시 표준 에러 (stderr) 메시지
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:112:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(M<=1)
^~
rect.cpp:114:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return brut();
^~~~~~
# | 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... |