이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
const int MAXN = 3e3;
int n, m, dp[3][3];
string g[MAXN+1];
bool up(int i, int j){
return i > 2 && g[i-2][j] == 'R' && g[i-1][j] == 'G' && g[i][j] == 'W';
}
bool left(int i, int j){
return j > 2 && g[i][j-2] == 'R' && g[i][j-1] == 'G' && g[i][j] == 'W';
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1; i<=n; ++i) cin >> g[i], g[i] = ' ' + g[i];
for(int s=2; s<=n+m; ++s){
int i = max(1LL, s - m);
for(; i<=n && s-i; ++i){
int j = s - i, cur[3][3];
for(int a=0; a<3; ++a)
cur[a][0] = cur[a][1] = cur[a][2] = 0;
for(int a=0; a<3; ++a){
for(int b=0; b<3; ++b){
for(int c=0; c<3; ++c){
if(a == 1 && max(b, c) > a) continue;
if(a == 1 && !up(i, j)) continue;
if(a == 2 && !left(i, j)) continue;
cur[a][b] = max(cur[a][b], bool(a) + dp[b][c]);
}
}
}
swap(dp, cur);
}
for(int a=0; a<3; ++a)
for(int b=0; b<3; ++b)
dp[0][0] = max(dp[0][0], dp[a][b]);
for(int a=0; a<3; ++a)
for(int b=0; b<3; ++b)
dp[a][b] = dp[0][0];
}
cout << dp[0][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... |