#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;
st[sz]=0;
INDEX[sz++]=0;
for(int j=1;j<=m+1;j++){
while(sz>1&&st[sz-1]>=col[i][j]){
ans+=(j-INDEX[sz-2]-1ll)*st[sz-1];
sz--;
}
st[sz]=col[i][j];
INDEX[sz++]=j;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
99396 KB |
Output is correct |
2 |
Incorrect |
0 ms |
99396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |