#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int nax = 3111;
void maxi(int &a, int b) {
a = max(a, b);
}
int n, m;
char s[nax][nax];
bool in(int r, int c) {
return 1 <= r && r <= n && 1 <= c && c <= m;
}
int dp[nax][nax][2][2];
int daj(int r, int c) {
int naj = 0;
for(int i = 0; i < 2; ++i)
for(int j = 0; j < 2; ++j)
maxi(naj, dp[r][c][i][j]);
return naj;
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i)
scanf("%s", s[i] + 1);
for(int r = 1; r <= n; ++r)
for(int c = m; 1 <= c; --c)
for(int g = 0; g < 2; ++g)
for(int d = 0; d < 2; ++d) {
maxi(dp[r][c][0][0], dp[r - 1][c + 1][g][d]);
if(!(s[r][c] == 'G')) continue;
if(in(r - 1, c) && s[r - 1][c] == 'R' && g == 0) {
if(in(r + 1, c) && s[r + 1][c] == 'W')
maxi(dp[r][c][0][1], dp[r - 1][c + 1][g][d] + 1);
if(in(r, c + 1) && s[r][c + 1] == 'W' && d == 0)
maxi(dp[r][c][0][0], dp[r - 1][c + 1][g][d] + 1);
}
if(in(r, c + 1) && s[r][c + 1] == 'W' && d == 0)
if(in(r, c - 1) && s[r][c - 1] == 'R')
maxi(dp[r][c][1][0], dp[r - 1][c + 1][g][d] + 1);
if(in(r, c - 1) && s[r][c - 1] == 'R' && in(r + 1, c) && s[r + 1][c] == 'W')
maxi(dp[r][c][1][1], dp[r - 1][c + 1][g][d] + 1);
}
int ans = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
if(i == n || j == 1)
ans += daj(i, j);
printf("%d\n", ans);
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:39:8: 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 |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |