#include<iostream>
using namespace std;
typedef long long ll;
ll n,m,col[3333][3333],st[3333],INDEX[3333];
char a[3333][3333];
int main(){
ios::sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>&a[i][1];
for(int j=1;j<=m;j++)
for(int i=1;i<=n;i++)
if(a[i][j]=='R')col[i][j]=col[i-1][j]+(a[i][j]=='R');
ll ans=0;
for(int i=1;i<=n;i++){
int sz=0,cnt;
st[sz]=0;
INDEX[sz++]=0;
for(int j=1;j<=m+1;j++){
cnt=0;
while(sz>1&&st[sz-1]>=col[i][j]){
ans+=(j-INDEX[sz-2]-1ll)*st[sz-1];
if(cnt){
ans-=(j-INDEX[sz-2]-1ll)*st[sz-1];
ans+=(INDEX[sz-1]-INDEX[sz-2])*st[sz-1]*(j-INDEX[sz-1]);
}
sz--;
cnt++;
}
st[sz]=col[i][j];
INDEX[sz++]=j;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
99400 KB |
Output is correct |
2 |
Correct |
0 ms |
99400 KB |
Output is correct |
3 |
Correct |
0 ms |
99400 KB |
Output is correct |
4 |
Correct |
0 ms |
99400 KB |
Output is correct |
5 |
Correct |
0 ms |
99400 KB |
Output is correct |
6 |
Correct |
0 ms |
99400 KB |
Output is correct |
7 |
Correct |
0 ms |
99400 KB |
Output is correct |
8 |
Correct |
0 ms |
99400 KB |
Output is correct |
9 |
Correct |
0 ms |
99400 KB |
Output is correct |
10 |
Correct |
0 ms |
99400 KB |
Output is correct |
11 |
Correct |
0 ms |
99400 KB |
Output is correct |
12 |
Correct |
0 ms |
99400 KB |
Output is correct |
13 |
Correct |
0 ms |
99400 KB |
Output is correct |
14 |
Correct |
0 ms |
99400 KB |
Output is correct |
15 |
Correct |
0 ms |
99400 KB |
Output is correct |
16 |
Correct |
0 ms |
99400 KB |
Output is correct |
17 |
Correct |
0 ms |
99400 KB |
Output is correct |
18 |
Correct |
0 ms |
99400 KB |
Output is correct |
19 |
Correct |
0 ms |
99400 KB |
Output is correct |
20 |
Correct |
0 ms |
99400 KB |
Output is correct |
21 |
Correct |
0 ms |
99400 KB |
Output is correct |
22 |
Correct |
4 ms |
99400 KB |
Output is correct |
23 |
Correct |
4 ms |
99400 KB |
Output is correct |
24 |
Correct |
0 ms |
99400 KB |
Output is correct |
25 |
Correct |
4 ms |
99400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
99400 KB |
Output is correct |
2 |
Correct |
3 ms |
99400 KB |
Output is correct |
3 |
Correct |
11 ms |
99400 KB |
Output is correct |
4 |
Correct |
13 ms |
99400 KB |
Output is correct |
5 |
Correct |
12 ms |
99400 KB |
Output is correct |
6 |
Correct |
12 ms |
99400 KB |
Output is correct |
7 |
Correct |
9 ms |
99400 KB |
Output is correct |
8 |
Correct |
5 ms |
99400 KB |
Output is correct |
9 |
Correct |
17 ms |
99400 KB |
Output is correct |
10 |
Correct |
12 ms |
99400 KB |
Output is correct |
11 |
Correct |
16 ms |
99400 KB |
Output is correct |
12 |
Correct |
0 ms |
99400 KB |
Output is correct |
13 |
Correct |
16 ms |
99400 KB |
Output is correct |
14 |
Correct |
0 ms |
99400 KB |
Output is correct |
15 |
Correct |
5 ms |
99400 KB |
Output is correct |
16 |
Correct |
0 ms |
99400 KB |
Output is correct |
17 |
Correct |
0 ms |
99400 KB |
Output is correct |
18 |
Correct |
5 ms |
99400 KB |
Output is correct |
19 |
Correct |
6 ms |
99400 KB |
Output is correct |
20 |
Correct |
0 ms |
99400 KB |
Output is correct |
21 |
Correct |
4 ms |
99400 KB |
Output is correct |
22 |
Correct |
0 ms |
99400 KB |
Output is correct |
23 |
Correct |
12 ms |
99400 KB |
Output is correct |
24 |
Correct |
9 ms |
99400 KB |
Output is correct |
25 |
Correct |
7 ms |
99400 KB |
Output is correct |
26 |
Correct |
3 ms |
99400 KB |
Output is correct |
27 |
Correct |
7 ms |
99400 KB |
Output is correct |
28 |
Correct |
6 ms |
99400 KB |
Output is correct |
29 |
Correct |
8 ms |
99400 KB |
Output is correct |
30 |
Correct |
6 ms |
99400 KB |
Output is correct |
31 |
Correct |
178 ms |
99400 KB |
Output is correct |
32 |
Correct |
143 ms |
99400 KB |
Output is correct |
33 |
Correct |
140 ms |
99400 KB |
Output is correct |
34 |
Correct |
151 ms |
99400 KB |
Output is correct |
35 |
Correct |
167 ms |
99400 KB |
Output is correct |
36 |
Correct |
184 ms |
99400 KB |
Output is correct |
37 |
Correct |
201 ms |
99400 KB |
Output is correct |
38 |
Correct |
237 ms |
99400 KB |
Output is correct |
39 |
Correct |
231 ms |
99400 KB |
Output is correct |
40 |
Correct |
161 ms |
99400 KB |
Output is correct |