이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<string> S(H);
for (int i = 0; i < H; ++i) {
cin >> S[i];
}
int ans = 0;
for (int i = 0; i <= H + W - 4; ++i) {
vector<int> seq(2 * H);
for (int j = 0; j < H; ++j) {
int x = j, y = i - j;
if (y < 0 || y >= W) continue;
if (x <= H - 3 && S[x][y] == 'R' && S[x + 1][y] == 'G' && S[x + 2][y] == 'W') {
seq[(H - x - 1) * 2 - 1] = 1;
}
if (y <= W - 3 && S[x][y] == 'R' && S[x][y + 1] == 'G' && S[x][y + 2] == 'W') {
seq[(H - x - 1) * 2] = 1;
}
}
vector<int> dp(8);
for (int j = 0; j < 2 * H; ++j) {
vector<int> ndp(8);
for (int k = 0; k < 8; ++k) {
ndp[(k << 1) & 7] = max(ndp[(k << 1) & 7], dp[k]);
if (seq[j] == 1 && !(k & 1) && (j % 2 == 0 || !(k & 4))) {
ndp[((k << 1) | 1) & 7] = max(ndp[((k << 1) | 1) & 7], dp[k] + 1);
}
}
dp = ndp;
}
ans += *max_element(dp.begin(), dp.end());
}
cout << ans << endl;
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... |