이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define all(v) v.begin() , v.end()
using namespace std;
const int INF = 1e9;
const int N = 3005;
int dp[N][N][2];
bitset<N> ch[N][2];
void _(){
int n,m,ans=0;
cin >> n >> m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ch[i][0][j]=ch[i][1][j]=1;
vector<string> v;
v.push_back("$$$");
for(int i=0;i<n;i++){
string s;cin >> s;
s="$"+s+"$";
v.push_back(s);
}
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
if(v[i][j]!='R'){
dp[i][j][0]=dp[i][j][1]=-INF;
ch[i][0][j]=ch[i][1][j]=0;
continue;
}
bool ok0=0,ok1=0;
if(i+2<=n && v[i+1][j]=='G' && v[i+2][j]=='W') ok0=1;
if(j+2<=m && v[i][j+1]=='G' && v[i][j+2]=='W') ok1=1;
if(!ok0 && !ok1){
dp[i][j][0]=dp[i][j][1]=-INF;
ch[i][0][j]=ch[i][1][j]=0;
continue;
}
if(ok0){
dp[i][j][0]=1;
if(i-1>=1 && j+1<=m && v[i-1][j+1]=='R'){
dp[i][j][0]=max(dp[i][j][0],max(dp[i-1][j+1][1],dp[i-1][j+1][0])+1);
ch[i-1][1][j+1]=ch[i-1][0][j+1]=0;
}
}
else{
ch[i][0][j]=0;
dp[i][j][0]=-INF;
}
if(ok1){
dp[i][j][1]=1;
if(i-1>=1 && j+1<=m && v[i-1][j+1]=='R'){
dp[i][j][1]=max(dp[i][j][1],dp[i-1][j+1][1]+1);
ch[i-1][1][j+1]=0;
}
if(i-2>=1 && j+2<=m && v[i-2][j+2]=='R'){
dp[i][j][1]=max(dp[i][j][1],dp[i-2][j+2][1]+1);
ch[i-2][1][j+2]=0;
}
}
else{
ch[i][1][j]=0;
dp[i][j][1]=-INF;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int cur=0;
if(ch[i][0][j]) cur=max(cur,dp[i][j][0]);
if(ch[i][1][j]) cur=max(cur,dp[i][j][1]);
ans+=cur;
}
}
cout << ans << '\n';
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |