#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define s <<" "<<
#define c <<" : "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN=3000, INF=10000000000;
///500,000,000
int N, M, out, dp[2*MAXN][3]; /// 0 is none, 1 is up, 2 is side
char grid[MAXN][MAXN];
int up[MAXN][MAXN], side[MAXN][MAXN];
main() {
//ifstream cin("test.in");
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
ffa cin >> grid[i][j];
For (i, 1, N-1) ffj if (grid[i-1][j] == 'R' && grid[i][j] == 'G' && grid[i+1][j] == 'W') up[i][j] = 1;
ffi For (j, 1, M-1) if (grid[i][j-1] == 'R' && grid[i][j] == 'G' && grid[i][j+1] == 'W') side[i][j] = 1;
For (i, 1, N+M-2) {
bool st = true;
int curr = 0;
for (int x =i, y = 0; x >= 0 && y < M; x--, y++) {
if (x >= N) continue;
//w<< i c x s y<<e;
if (st) {
dp[y][0] = 0;
dp[y][1] = up[x][y];
dp[y][2] = side[x][y];
st = false;
}
else {
dp[y][0] = max(dp[y-1][0], max(dp[y-1][1], dp[y-1][2]));
dp[y][1] = up[x][y] + max(dp[y-1][0], dp[y-1][1]);
dp[y][2] = side[x][y] + max(dp[y-1][0], dp[y-1][2]);
}
curr = max(max(curr, dp[y][0]), max(dp[y][1], dp[y][2]));
}
out += curr;
}
w<< out<<e;
}
Compilation message
dango_maker.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
23 | main() {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
492 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
1 ms |
492 KB |
Output is correct |
47 |
Correct |
1 ms |
492 KB |
Output is correct |
48 |
Correct |
1 ms |
492 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
1 ms |
492 KB |
Output is correct |
51 |
Correct |
1 ms |
492 KB |
Output is correct |
52 |
Correct |
1 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
492 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
1 ms |
492 KB |
Output is correct |
47 |
Correct |
1 ms |
492 KB |
Output is correct |
48 |
Correct |
1 ms |
492 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
1 ms |
492 KB |
Output is correct |
51 |
Correct |
1 ms |
492 KB |
Output is correct |
52 |
Correct |
1 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
492 KB |
Output is correct |
54 |
Correct |
4 ms |
512 KB |
Output is correct |
55 |
Correct |
9 ms |
9836 KB |
Output is correct |
56 |
Correct |
5 ms |
620 KB |
Output is correct |
57 |
Correct |
10 ms |
16364 KB |
Output is correct |
58 |
Correct |
63 ms |
27244 KB |
Output is correct |
59 |
Correct |
512 ms |
159212 KB |
Output is correct |
60 |
Correct |
508 ms |
158976 KB |
Output is correct |
61 |
Correct |
526 ms |
158828 KB |
Output is correct |
62 |
Correct |
4 ms |
492 KB |
Output is correct |
63 |
Correct |
502 ms |
158572 KB |
Output is correct |
64 |
Correct |
423 ms |
158956 KB |
Output is correct |
65 |
Correct |
414 ms |
158828 KB |
Output is correct |
66 |
Correct |
416 ms |
158928 KB |
Output is correct |
67 |
Correct |
352 ms |
45676 KB |
Output is correct |
68 |
Correct |
354 ms |
45932 KB |
Output is correct |
69 |
Correct |
371 ms |
56428 KB |
Output is correct |
70 |
Correct |
51 ms |
27884 KB |
Output is correct |
71 |
Correct |
50 ms |
27884 KB |
Output is correct |
72 |
Correct |
50 ms |
27884 KB |
Output is correct |
73 |
Correct |
50 ms |
27884 KB |
Output is correct |
74 |
Correct |
52 ms |
28012 KB |
Output is correct |
75 |
Correct |
50 ms |
27884 KB |
Output is correct |
76 |
Correct |
50 ms |
27884 KB |
Output is correct |
77 |
Correct |
51 ms |
27884 KB |
Output is correct |
78 |
Correct |
50 ms |
27884 KB |
Output is correct |
79 |
Correct |
51 ms |
27884 KB |
Output is correct |
80 |
Correct |
51 ms |
27904 KB |
Output is correct |
81 |
Correct |
52 ms |
27884 KB |
Output is correct |
82 |
Correct |
52 ms |
27884 KB |
Output is correct |
83 |
Correct |
50 ms |
27884 KB |
Output is correct |
84 |
Correct |
50 ms |
27996 KB |
Output is correct |
85 |
Correct |
50 ms |
27884 KB |
Output is correct |
86 |
Correct |
51 ms |
27884 KB |
Output is correct |
87 |
Correct |
51 ms |
27884 KB |
Output is correct |
88 |
Correct |
52 ms |
27884 KB |
Output is correct |
89 |
Correct |
50 ms |
27884 KB |
Output is correct |
90 |
Correct |
52 ms |
27884 KB |
Output is correct |