| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 15807 | comet | 빨간 직사각형 (kriii3_QQ) | C++98 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
