이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e3 + 10;
char s[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][3];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 1; i <= N; i++) {
cin >> (s[i] + 1);
}
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= M; j++) {
dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
if(s[i][j - 1] == 'R' and s[i][j] == 'G' and s[i][j + 1] == 'W') {
dp[i][j][1] = 1 + max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][1]);
}
if(s[i - 1][j] == 'R' and s[i][j] == 'G' and s[i + 1][j] == 'W') {
dp[i][j][2] = 1 + max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][2]);
}
}
}
int ans = 0;
for(int i = 1; i <= N; i++) {
ans += max({dp[i][1][0], dp[i][1][1], dp[i][1][2]});
}
for(int i = 2; i <= M; i++) {
ans += max({dp[N][i][0], dp[N][i][1], dp[N][i][2]});
}
cout << ans;
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... |