/*
https://codeforces.com/blog/entry/57637?#comment-413356
*/
#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:26:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
684 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
2 ms |
788 KB |
Output is correct |
14 |
Correct |
2 ms |
824 KB |
Output is correct |
15 |
Correct |
2 ms |
824 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
684 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
2 ms |
788 KB |
Output is correct |
14 |
Correct |
2 ms |
824 KB |
Output is correct |
15 |
Correct |
2 ms |
824 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
17 |
Correct |
2 ms |
824 KB |
Output is correct |
18 |
Correct |
3 ms |
824 KB |
Output is correct |
19 |
Correct |
2 ms |
824 KB |
Output is correct |
20 |
Correct |
2 ms |
824 KB |
Output is correct |
21 |
Correct |
2 ms |
824 KB |
Output is correct |
22 |
Correct |
2 ms |
824 KB |
Output is correct |
23 |
Correct |
2 ms |
824 KB |
Output is correct |
24 |
Correct |
2 ms |
824 KB |
Output is correct |
25 |
Correct |
2 ms |
824 KB |
Output is correct |
26 |
Correct |
2 ms |
824 KB |
Output is correct |
27 |
Correct |
2 ms |
824 KB |
Output is correct |
28 |
Correct |
2 ms |
896 KB |
Output is correct |
29 |
Correct |
2 ms |
896 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
31 |
Correct |
2 ms |
896 KB |
Output is correct |
32 |
Correct |
2 ms |
896 KB |
Output is correct |
33 |
Correct |
3 ms |
896 KB |
Output is correct |
34 |
Correct |
3 ms |
896 KB |
Output is correct |
35 |
Correct |
2 ms |
964 KB |
Output is correct |
36 |
Correct |
2 ms |
964 KB |
Output is correct |
37 |
Correct |
3 ms |
964 KB |
Output is correct |
38 |
Correct |
3 ms |
964 KB |
Output is correct |
39 |
Correct |
2 ms |
964 KB |
Output is correct |
40 |
Correct |
3 ms |
964 KB |
Output is correct |
41 |
Correct |
2 ms |
964 KB |
Output is correct |
42 |
Correct |
2 ms |
964 KB |
Output is correct |
43 |
Correct |
2 ms |
964 KB |
Output is correct |
44 |
Correct |
2 ms |
964 KB |
Output is correct |
45 |
Correct |
2 ms |
964 KB |
Output is correct |
46 |
Correct |
2 ms |
964 KB |
Output is correct |
47 |
Correct |
2 ms |
964 KB |
Output is correct |
48 |
Correct |
2 ms |
964 KB |
Output is correct |
49 |
Correct |
2 ms |
964 KB |
Output is correct |
50 |
Correct |
2 ms |
964 KB |
Output is correct |
51 |
Correct |
2 ms |
964 KB |
Output is correct |
52 |
Correct |
2 ms |
964 KB |
Output is correct |
53 |
Correct |
3 ms |
964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
2 ms |
684 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
2 ms |
788 KB |
Output is correct |
14 |
Correct |
2 ms |
824 KB |
Output is correct |
15 |
Correct |
2 ms |
824 KB |
Output is correct |
16 |
Correct |
2 ms |
824 KB |
Output is correct |
17 |
Correct |
2 ms |
824 KB |
Output is correct |
18 |
Correct |
3 ms |
824 KB |
Output is correct |
19 |
Correct |
2 ms |
824 KB |
Output is correct |
20 |
Correct |
2 ms |
824 KB |
Output is correct |
21 |
Correct |
2 ms |
824 KB |
Output is correct |
22 |
Correct |
2 ms |
824 KB |
Output is correct |
23 |
Correct |
2 ms |
824 KB |
Output is correct |
24 |
Correct |
2 ms |
824 KB |
Output is correct |
25 |
Correct |
2 ms |
824 KB |
Output is correct |
26 |
Correct |
2 ms |
824 KB |
Output is correct |
27 |
Correct |
2 ms |
824 KB |
Output is correct |
28 |
Correct |
2 ms |
896 KB |
Output is correct |
29 |
Correct |
2 ms |
896 KB |
Output is correct |
30 |
Correct |
2 ms |
896 KB |
Output is correct |
31 |
Correct |
2 ms |
896 KB |
Output is correct |
32 |
Correct |
2 ms |
896 KB |
Output is correct |
33 |
Correct |
3 ms |
896 KB |
Output is correct |
34 |
Correct |
3 ms |
896 KB |
Output is correct |
35 |
Correct |
2 ms |
964 KB |
Output is correct |
36 |
Correct |
2 ms |
964 KB |
Output is correct |
37 |
Correct |
3 ms |
964 KB |
Output is correct |
38 |
Correct |
3 ms |
964 KB |
Output is correct |
39 |
Correct |
2 ms |
964 KB |
Output is correct |
40 |
Correct |
3 ms |
964 KB |
Output is correct |
41 |
Correct |
2 ms |
964 KB |
Output is correct |
42 |
Correct |
2 ms |
964 KB |
Output is correct |
43 |
Correct |
2 ms |
964 KB |
Output is correct |
44 |
Correct |
2 ms |
964 KB |
Output is correct |
45 |
Correct |
2 ms |
964 KB |
Output is correct |
46 |
Correct |
2 ms |
964 KB |
Output is correct |
47 |
Correct |
2 ms |
964 KB |
Output is correct |
48 |
Correct |
2 ms |
964 KB |
Output is correct |
49 |
Correct |
2 ms |
964 KB |
Output is correct |
50 |
Correct |
2 ms |
964 KB |
Output is correct |
51 |
Correct |
2 ms |
964 KB |
Output is correct |
52 |
Correct |
2 ms |
964 KB |
Output is correct |
53 |
Correct |
3 ms |
964 KB |
Output is correct |
54 |
Correct |
7 ms |
964 KB |
Output is correct |
55 |
Correct |
16 ms |
10388 KB |
Output is correct |
56 |
Correct |
8 ms |
10388 KB |
Output is correct |
57 |
Correct |
16 ms |
16956 KB |
Output is correct |
58 |
Correct |
86 ms |
27924 KB |
Output is correct |
59 |
Correct |
819 ms |
160616 KB |
Output is correct |
60 |
Correct |
790 ms |
169488 KB |
Output is correct |
61 |
Correct |
820 ms |
178316 KB |
Output is correct |
62 |
Correct |
7 ms |
178316 KB |
Output is correct |
63 |
Correct |
775 ms |
186812 KB |
Output is correct |
64 |
Correct |
679 ms |
195532 KB |
Output is correct |
65 |
Correct |
692 ms |
204316 KB |
Output is correct |
66 |
Correct |
668 ms |
212916 KB |
Output is correct |
67 |
Correct |
451 ms |
212916 KB |
Output is correct |
68 |
Correct |
451 ms |
212916 KB |
Output is correct |
69 |
Correct |
449 ms |
212916 KB |
Output is correct |
70 |
Correct |
61 ms |
212916 KB |
Output is correct |
71 |
Correct |
61 ms |
212916 KB |
Output is correct |
72 |
Correct |
72 ms |
212916 KB |
Output is correct |
73 |
Correct |
73 ms |
212916 KB |
Output is correct |
74 |
Correct |
70 ms |
212916 KB |
Output is correct |
75 |
Correct |
74 ms |
212916 KB |
Output is correct |
76 |
Correct |
72 ms |
212916 KB |
Output is correct |
77 |
Correct |
72 ms |
212916 KB |
Output is correct |
78 |
Correct |
69 ms |
212916 KB |
Output is correct |
79 |
Correct |
71 ms |
212916 KB |
Output is correct |
80 |
Correct |
68 ms |
212916 KB |
Output is correct |
81 |
Correct |
73 ms |
212916 KB |
Output is correct |
82 |
Correct |
69 ms |
212916 KB |
Output is correct |
83 |
Correct |
73 ms |
212916 KB |
Output is correct |
84 |
Correct |
70 ms |
212916 KB |
Output is correct |
85 |
Correct |
62 ms |
212916 KB |
Output is correct |
86 |
Correct |
71 ms |
212916 KB |
Output is correct |
87 |
Correct |
73 ms |
212916 KB |
Output is correct |
88 |
Correct |
70 ms |
212916 KB |
Output is correct |
89 |
Correct |
69 ms |
212916 KB |
Output is correct |
90 |
Correct |
59 ms |
212916 KB |
Output is correct |