This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int D_MAX = 3000;
int N, M;
char mat[D_MAX + 2][D_MAX + 2];
bool H[D_MAX + 2][D_MAX + 2];
bool V[D_MAX + 2][D_MAX + 2];
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(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] == 'G') {
if (1 < j && j < M && mat[i][j - 1] == 'R' && mat[i][j + 1] == 'W') {
H[i][j] = true;
}
if (1 < i && i < N && mat[i - 1][j] == 'R' && mat[i + 1][j] == 'W') {
V[i][j] = true;
}
}
}
}
int answer = 0;
for (int s = 1 + 1; s <= N + M; s++) {
int i1 = max(1, s - M), i2 = min(N, s - 1);
int dp[2][3];
dp[0][0] = dp[0][1] = dp[0][2] = 0;
for (int i = i1; i <= i2; i++) {
int j = s - i;
dp[1][0] = max({dp[0][0], dp[0][1], dp[0][2]});
if (H[i][j] == true) {
dp[1][1] = max(dp[0][0], dp[0][1]) + 1;
} else {
dp[1][1] = 0;
}
if (V[i][j] == true) {
dp[1][2] = max(dp[0][0], dp[0][2]) + 1;
} else {
dp[1][2] = 0;
}
swap(dp[0], dp[1]);
}
answer += max({dp[0][0], dp[0][1], dp[0][2]});
}
cout << answer << "\n";
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... |