Submission #15810

#TimeUsernameProblemLanguageResultExecution timeMemory
15810comet빨간 직사각형 (kriii3_QQ)C++98
20 / 20
236 ms99400 KiB
#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]){ //cout<<"sz= "<<sz<<endl; 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]); //ans+=(INDEX[sz-1]-INDEX[sz-2])*(j-INDEX[sz-1]); } sz--; cnt++; //cout<<"ans= "<<ans<<endl; } st[sz]=col[i][j]; INDEX[sz++]=j; //cout<<j<<" "<<ans<<endl; } //cout<<"i= "<<i<<endl; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...