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 <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, m;
char a[N][N];
bool chcol(int x, int y) {
if (a[x][y] == 'R' && a[x + 1][y] == 'G' && a[x + 2][y] == 'W') return true;
return false;
}
bool chrow(int x, int y) {
if (a[x][y] == 'R' && a[x][y + 1] == 'G' && a[x][y + 2] == 'W') return true;
return false;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
int ans = 0;
for (int t = 2; t <= n + m - 2; t++) {
vector<vector<int>> dp(3, vector<int>(3));
int pos = 0;
for (int j = t > n ? t - n : 1; j < t; j++) {
int i = t - j;
pos++;
int cur = pos % 3, prv = (pos - 1 + 3) % 3, PRV = (pos - 2 + 3) % 3;
dp[cur][0] = max({dp[prv][0], dp[prv][1], dp[prv][2]});
if (chrow(i, j)) dp[cur][1] = max({dp[prv][0], dp[prv][1], dp[prv][2]}) + 1;
if (chcol(i, j)) dp[cur][2] = max({dp[PRV][0], dp[PRV][2], dp[prv][2]}) + 1;
}
int cur = pos % 3;
ans += max({dp[cur][0], dp[cur][1], dp[cur][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... |