이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
// R
// RG
// RGW
// GW
// W
int solve(vector<int> d, vector<int> r) {
int n = d.size();
vector<vector<int>> dp(3, vector<int>(3, 0));
for (int i = 0; i < n; ++i) {
vector<vector<int>> ndp(3, vector<int>(3, 0));
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
for (int z = 0; z < 3; ++z) {
if (z == 1 && (x == 2 || y == 2 || !d[i])) continue;
if (z == 2 && (x == 1 || y == 1 || !r[i])) continue;
ndp[y][z] = max(ndp[y][z], dp[x][y] + !!z);
}
}
}
dp = ndp;
}
int ans = 0;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) ans = max(ans, dp[i][j]);
}
return ans;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<char>> grid(n, vector<char>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> grid[i][j];
}
}
auto can_down = [&](int x, int y) {
if (x + 2 < n && grid[x][y] == 'R' && grid[x + 1][y] == 'G' && grid[x + 2][y] == 'W') return 1;
return 0;
};
auto can_right = [&](int x, int y) {
if (y + 2 < m && grid[x][y] == 'R' && grid[x][y + 1] == 'G' && grid[x][y + 2] == 'W') return 1;
return 0;
};
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i == 0 || j == 0) {
vector<int> d, r;
int curi = i, curj = j;
while (curi < n && curj < m) {
d.push_back(can_down(curi, curj));
r.push_back(can_right(curi, curj));
++curi;
++curj;
}
ans += solve(d, r);
}
}
}
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... |