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>
#include <set>
#include <algorithm>
using namespace std;
const int nmax = 3007;
char mat[nmax][nmax];
int jos[nmax][nmax], dr[nmax][nmax], dp[nmax][nmax][3];
int32_t main() {
int n, m, ans = 0;
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cin >> mat[i][j];
}
}
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
if(mat[i][j - 1] == 'R' && mat[i][j] == 'G' && mat[i][j + 1] == 'W') {
dr[i][j] = 1;
}
if(mat[i - 1][j] == 'R' && mat[i][j] == 'G' && mat[i + 1][j] == 'W') {
jos[i][j] = 1;
}
}
}
int l = 1, c = 1, x = n + m;
while(x > 1) {
int i = l, j = c;
dp[i][j][0] = 0;
dp[i][j][1] = dr[i][j];
dp[i][j][2] = jos[i][j];
i --;
j ++;
while(j <= m && i > 0) {
for(int d = 0; d <= 2; d ++) {
dp[i][j][0] = max(dp[i][j][0], dp[i + 1][j - 1][d]);
}
dp[i][j][1] = max(dp[i + 1][j - 1][1], dp[i + 1][j - 1][0]) + dr[i][j];
dp[i][j][2] = max(dp[i + 1][j - 1][2], dp[i + 1][j - 1][0]) + jos[i][j];
i --;
j ++;
}
i ++;
j --;
ans = ans + max({dp[i][j][1], dp[i][j][2], dp[i][j][0]});
l ++;
if(l > n) {
l = n;
c ++;
}
x --;
}
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... |