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<cstdio>
char a[3333][3333];
int d[3333][3333];
int s[3333],p[3333],sn;
int main()
{
long long r=0;
int i,j,n,m,t;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%s",a[i]+1);
for(j=1;j<=m;j++)
{
d[i][j]=d[i][j-1]+1;
if(a[i][j]=='B')d[i][j]=0;
}
}
for(j=1;j<=m;j++)
{
sn=t=0;
s[sn]=0;
p[sn]=0;
sn++;
for(i=1;i<=n;i++)
{
while(sn>=2&&s[sn-1]>d[i][j])
{
t-=s[sn-1]*(p[sn-1]-p[sn-2]);
sn--;
}
t+=d[i][j]*(i-p[sn-1]);
s[sn]=d[i][j];
p[sn]=i;
sn++;
r+=t;
}
}
printf("%lld",r);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |