# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
15807 | comet | 빨간 직사각형 (kriii3_QQ) | C++98 | 0 ms | 0 KiB |
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>
#include<cstring>
using namespace std;
int 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');
int 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++){
//for(int k=0;k<sz;k++)cout<<st[k]<<" ";
////cout<<endl;
//for(int k=0;k<sz;k++)cout<<index[k]<<" ";
while(sz>1&&st[sz-1]>=col[i][j]){
//cout<<"wow "<<j<<" "<<index[sz-2]<<" "<<st[sz-1]<<endl;
ans+=(j-index[sz-2]-1)*st[sz-1];
sz--;
}
//cout<<endl<<"ans= "<<ans<<endl<<endl;
st[sz]=col[i][j];
index[sz++]=j;
}
}
cout<<ans;
}