Submission #15160

#TimeUsernameProblemLanguageResultExecution timeMemory
15160gs13068빨간 직사각형 (kriii3_QQ)C++98
20 / 20
269 ms55352 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...