This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int h, w;
vector<string> s;
int solve(int y, int x) {
vector<int> v;
for (int k = 0; y - k >= 0 && x + k < w; k++) {
int i = y - k;
int j = x + k;
if (s[i][j] != 'G') {
v.push_back(0);
continue;
}
int a = 0;
if (j > 0 && j + 1 < w && s[i][j - 1] == 'R' && s[i][j + 1] == 'W') {
a++;
}
if (i > 0 && i + 1 < h && s[i - 1][j] == 'R' && s[i + 1][j] == 'W') {
a += 2;
}
v.push_back(a);
}
vector<vector<int>> dp((int) v.size() + 1, vector<int>(2, 0));
for (int i = 0; i < (int) v.size(); i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
int tmp = dp[i][j];
if ((v[i] >> k & 1) && j == k) {
tmp++;
}
dp[i + 1][k] = max(dp[i + 1][k], tmp);
}
}
}
return max(dp[(int) v.size()][0], dp[(int) v.size()][1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w;
s = vector<string>(h);
for (int i = 0; i < h; i++) {
cin >> s[i];
}
int ans = 0;
for (int i = 0; i < h; i++) {
ans += solve(i, 0);
}
for (int i = 1; i < w; i++) {
ans += solve(h - 1, i);
}
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... |