이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 3e3;
char v[N][N];
int n,m;
int ans = 0;
bool ok(int x,int y,int id){
if(id == 0){
return 0 <= x && x <= n - 1 && 0 <= y && y <= m - 3 && v[x][y] == 'R' && v[x][y + 1] == 'G' && v[x][y + 2] == 'W';
}else{
return 0 <= x && x <= n - 3 && 0 <= y && y <= m - 1 && v[x][y] == 'R' && v[x + 1][y] == 'G' && v[x + 2][y] == 'W';
}
}
int dp[N][N][2];
int main(){
cin>>n>>m;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
cin>>v[i][j];
}
}
for(int i = n - 1;i >= 0;i--){
for(int j = 0;j < m;j++){
dp[i][j][0] = max(ok(i,j - 1,0) + (i + 1 < n && j - 1 >= 0?dp[i + 1][j - 1][0]:0),dp[i][j][0]);
dp[i][j][0] = max(ok(i,j - 1,0) + (i + 2 < n && j - 2 >= 0?dp[i + 2][j - 2][1]:0),dp[i][j][0]);
dp[i][j][1] = max(ok(i - 1,j,1) + (i + 1 < n && j - 1 >= 0?dp[i + 1][j - 1][1]:0),dp[i][j][1]);
dp[i][j][1] = max(ok(i - 1,j,1) + (i + 2 < n && j - 2 >= 0?dp[i + 2][j - 2][0]:0),dp[i][j][1]);
if(i == 0 || j == m - 1){
ans+=max(dp[i][j][0],dp[i][j][1]);
}
}
}
cout<<ans<<'\n';
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... |