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 MAX_N = 3e3 + 10;
char s[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][3];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 1; i <= N; i++) {
cin >> (s[i] + 1);
}
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= M; j++) {
dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
if(s[i][j - 1] == 'R' and s[i][j] == 'G' and s[i][j + 1] == 'W') {
dp[i][j][1] = 1 + max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][1]);
}
if(s[i - 1][j] == 'R' and s[i][j] == 'G' and s[i + 1][j] == 'W') {
dp[i][j][2] = 1 + max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][2]);
}
}
}
int ans = 0;
for(int i = 1; i <= N; i++) {
ans += max({dp[i][1][0], dp[i][1][1], dp[i][1][2]});
}
for(int i = 2; i <= M; i++) {
ans += max({dp[N][i][0], dp[N][i][1], dp[N][i][2]});
}
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... |