이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector g(n + 1, vector<char>(m + 1));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> g[i][j];
}
}
int ans = 0;
for(int s = 2; s <= n + m; s++) {
vector dp(n + 1, vector<int>(3));
int p = 0;
for(int i = 1, j = s - i; i <= n; i++, j--) {
if(!(1 <= j && j <= m)) {
continue;
}
dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
if(g[i][j] == 'G') {
if(1 < i && i < n && g[i - 1][j] == 'R' && g[i + 1][j] == 'W') {
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
}
if(1 < j && j < m && g[i][j - 1] == 'R' && g[i][j + 1] == 'W') {
dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
}
}
p = i;
}
ans += max({dp[p][0], dp[p][1], dp[p][2]});
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |