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;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;
template <typename T> inline void Read(T &x) {
char c = getchar();
bool f = false;
for (x = 0; !isdigit(c); c = getchar()) {
if (c == '-') {
f = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
}
if (f) {
x = -x;
}
}
template <typename T> inline bool CheckMax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
template <typename T> inline bool CheckMin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
const int N = 3005;
int n, m, ans, f[N][3], g[N][N];
char s[N][N];
int main() {
#ifdef wxh010910
freopen("d.in", "r", stdin);
#endif
Read(n), Read(m);
for (int i = 1; i <= n; ++i) {
scanf("%s", s[i] + 1);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i - 1][j] == 'R' && s[i][j] == 'G' && s[i + 1][j] == 'W') {
g[i][j] |= 1;
}
if (s[i][j - 1] == 'R' && s[i][j] == 'G' && s[i][j + 1] == 'W') {
g[i][j] |= 2;
}
}
}
for (int s = 2; s <= n + m; ++s) {
for (int i = max(1, s - m), j = s - i; i <= min(n, s - 1); ++i, --j) {
if (i == max(1, s - m)) {
f[i][0] = 0, f[i][1] = g[i][j] & 1, f[i][2] = g[i][j] >> 1 & 1;
} else {
f[i][0] = max(f[i - 1][0], max(f[i - 1][1], f[i - 1][2])), f[i][1] = f[i][2] = 0;
if (g[i][j] & 1) {
f[i][1] = max(f[i - 1][0], f[i - 1][1]) + 1;
}
if (g[i][j] & 2) {
f[i][2] = max(f[i - 1][0], f[i - 1][2]) + 1;
}
}
}
ans += max(f[min(n, s - 1)][0], max(f[min(n, s - 1)][1], f[min(n, s - 1)][2]));
}
printf("%d\n", ans);
#ifdef wxh010910
Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:52:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s[i] + 1);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |