This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
check for(ij)
*/
#include<bits/stdc++.h>
using namespace std;
const int N = (int)3e3 + 5;
int n, m, ans, dp[N][4];
char c[N][N];
bool validCell (int x, int y) { return x >= 1 && y >= 1 && x <= n && y <= m; }
bool downCheck (int x, int y) {
return validCell(x, y) && validCell(x + 1, y) && validCell(x + 2, y) && c[x][y] == 'R' && c[x + 1][y] == 'G' && c[x + 2][y] == 'W';
}
bool rightCheck (int x, int y) {
return validCell(x, y) && validCell(x, y + 1) && validCell(x, y + 2) && c[x][y] == 'R' && c[x][y + 1] == 'G' && c[x][y + 2] == 'W';
}
void update (int &_a, int _b) {
_a = max(_a, _b);
}
int main () {
// freopen("test.INP", "r", stdin);
// freopen("Seeht.OUT", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) cin >> c[i][j];
}
for (int ij = 2; ij <= n + m - 2; ++ij) {
memset(dp, 0, sizeof dp);
for (int i = max(1, ij - m); i <= min(n, ij - 1); ++i) {
int j = ij - i;
for (int mask = 0; mask < 4; ++mask) {
update(dp[i][mask >> 1], dp[i - 1][mask]);
if (downCheck(i, j) ) update(dp[i][(mask >> 1) | 2], dp[i - 1][mask] + 1);
}
if (rightCheck(i, j) ) update(dp[i][0], dp[i - 1][0] + 1);
}
ans += max(dp[ min(n, ij - 1) ][0], max(dp[ min(n, ij - 1) ][1], max(dp[ min(n, ij - 1) ][2], dp[ min(n, ij - 1) ][3]) ) );
}
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... |