이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |