This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |