#include<cstdio>
#include<algorithm>
#include<cstring>
long long a,b,i,j,S,sum,p,u,q,w[3333][3333];
long long P[3333],Q[3333],max[3333];
char s[3333];
main()
{
scanf("%lld%lld",&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("%lld",a*(a+1)/2*b*(b+1)/2-S);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
87952 KB |
Output is correct |
2 |
Correct |
0 ms |
87952 KB |
Output is correct |
3 |
Correct |
0 ms |
87952 KB |
Output is correct |
4 |
Correct |
0 ms |
87952 KB |
Output is correct |
5 |
Correct |
0 ms |
87952 KB |
Output is correct |
6 |
Correct |
0 ms |
87952 KB |
Output is correct |
7 |
Correct |
0 ms |
87952 KB |
Output is correct |
8 |
Correct |
0 ms |
87952 KB |
Output is correct |
9 |
Correct |
0 ms |
87952 KB |
Output is correct |
10 |
Correct |
0 ms |
87952 KB |
Output is correct |
11 |
Correct |
0 ms |
87952 KB |
Output is correct |
12 |
Correct |
0 ms |
87952 KB |
Output is correct |
13 |
Correct |
0 ms |
87952 KB |
Output is correct |
14 |
Correct |
0 ms |
87952 KB |
Output is correct |
15 |
Correct |
0 ms |
87952 KB |
Output is correct |
16 |
Correct |
0 ms |
87952 KB |
Output is correct |
17 |
Correct |
0 ms |
87952 KB |
Output is correct |
18 |
Correct |
0 ms |
87952 KB |
Output is correct |
19 |
Correct |
0 ms |
87952 KB |
Output is correct |
20 |
Correct |
0 ms |
87952 KB |
Output is correct |
21 |
Correct |
3 ms |
87952 KB |
Output is correct |
22 |
Correct |
7 ms |
87952 KB |
Output is correct |
23 |
Correct |
6 ms |
87952 KB |
Output is correct |
24 |
Correct |
6 ms |
87952 KB |
Output is correct |
25 |
Correct |
3 ms |
87952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
87952 KB |
Output is correct |
2 |
Correct |
0 ms |
87952 KB |
Output is correct |
3 |
Correct |
18 ms |
87952 KB |
Output is correct |
4 |
Correct |
12 ms |
87952 KB |
Output is correct |
5 |
Correct |
22 ms |
87952 KB |
Output is correct |
6 |
Correct |
8 ms |
87952 KB |
Output is correct |
7 |
Correct |
6 ms |
87952 KB |
Output is correct |
8 |
Correct |
0 ms |
87952 KB |
Output is correct |
9 |
Correct |
11 ms |
87952 KB |
Output is correct |
10 |
Correct |
9 ms |
87952 KB |
Output is correct |
11 |
Correct |
11 ms |
87952 KB |
Output is correct |
12 |
Correct |
3 ms |
87952 KB |
Output is correct |
13 |
Correct |
10 ms |
87952 KB |
Output is correct |
14 |
Correct |
1 ms |
87952 KB |
Output is correct |
15 |
Correct |
0 ms |
87952 KB |
Output is correct |
16 |
Correct |
2 ms |
87952 KB |
Output is correct |
17 |
Correct |
0 ms |
87952 KB |
Output is correct |
18 |
Correct |
0 ms |
87952 KB |
Output is correct |
19 |
Correct |
2 ms |
87952 KB |
Output is correct |
20 |
Correct |
0 ms |
87952 KB |
Output is correct |
21 |
Correct |
0 ms |
87952 KB |
Output is correct |
22 |
Correct |
0 ms |
87952 KB |
Output is correct |
23 |
Correct |
12 ms |
87952 KB |
Output is correct |
24 |
Correct |
6 ms |
87952 KB |
Output is correct |
25 |
Correct |
7 ms |
87952 KB |
Output is correct |
26 |
Correct |
10 ms |
87952 KB |
Output is correct |
27 |
Correct |
7 ms |
87952 KB |
Output is correct |
28 |
Correct |
0 ms |
87952 KB |
Output is correct |
29 |
Correct |
0 ms |
87952 KB |
Output is correct |
30 |
Correct |
6 ms |
87952 KB |
Output is correct |
31 |
Correct |
111 ms |
87952 KB |
Output is correct |
32 |
Correct |
101 ms |
87952 KB |
Output is correct |
33 |
Correct |
88 ms |
87952 KB |
Output is correct |
34 |
Correct |
112 ms |
87952 KB |
Output is correct |
35 |
Correct |
158 ms |
87952 KB |
Output is correct |
36 |
Correct |
134 ms |
87952 KB |
Output is correct |
37 |
Correct |
160 ms |
87952 KB |
Output is correct |
38 |
Correct |
161 ms |
87952 KB |
Output is correct |
39 |
Correct |
225 ms |
87952 KB |
Output is correct |
40 |
Correct |
159 ms |
87952 KB |
Output is correct |