#include<cstdio>
#include<algorithm>
#include<cstring>
int a,b,i,j,S,sum,p,u,q,w[3333][3333];
int P[3333],Q[3333],max[3333];
char s[3333];
main()
{
scanf("%d%d",&a,&b);
for(i=1;i<=a;i++)
{
scanf("%s",s);
for(j=0;j<b;j++)
{
if(s[j]=='R')w[i][j+1]=1;
}
}
for(i=1;i<=a;i++)
{
p=0;
q=0;
sum=0;
for(j=1;j<=b;j++)
{
if(w[i][j]==0)
{
S+=i*j;
max[j]=i;
P[p++]=i;
Q[q++]=j;
sum=j*i;
}
else
{
while(max[j]>P[p-1]&&p>0)
{
u=q>1?Q[q-2]:0;
sum-=(Q[q-1]-u)*P[p-1];
p--;
q--;
}
u=q>0?Q[q-1]:0;
sum+=(j-u)*max[j];
P[p++]=max[j];
Q[q++]=j;
S+=sum;
}
}
}
printf("%d",a*(a+1)/2*b*(b+1)/2-S);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
44520 KB |
Output is correct |
2 |
Correct |
0 ms |
44520 KB |
Output is correct |
3 |
Correct |
0 ms |
44520 KB |
Output is correct |
4 |
Correct |
0 ms |
44520 KB |
Output is correct |
5 |
Correct |
0 ms |
44520 KB |
Output is correct |
6 |
Correct |
0 ms |
44520 KB |
Output is correct |
7 |
Correct |
0 ms |
44520 KB |
Output is correct |
8 |
Correct |
0 ms |
44520 KB |
Output is correct |
9 |
Correct |
0 ms |
44520 KB |
Output is correct |
10 |
Correct |
0 ms |
44520 KB |
Output is correct |
11 |
Correct |
0 ms |
44520 KB |
Output is correct |
12 |
Correct |
0 ms |
44520 KB |
Output is correct |
13 |
Correct |
0 ms |
44520 KB |
Output is correct |
14 |
Correct |
0 ms |
44520 KB |
Output is correct |
15 |
Correct |
0 ms |
44520 KB |
Output is correct |
16 |
Correct |
0 ms |
44520 KB |
Output is correct |
17 |
Correct |
0 ms |
44520 KB |
Output is correct |
18 |
Correct |
0 ms |
44520 KB |
Output is correct |
19 |
Correct |
0 ms |
44520 KB |
Output is correct |
20 |
Correct |
0 ms |
44520 KB |
Output is correct |
21 |
Correct |
3 ms |
44520 KB |
Output is correct |
22 |
Correct |
7 ms |
44520 KB |
Output is correct |
23 |
Incorrect |
7 ms |
44520 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |