#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(int)(e);i++)
#define FOE(i,s,e) for(int i=(s);i<=(int)(e);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define CLR(s) memset(s,0,sizeof(s))
#define PB push_back
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
const int MX_N = 3333;
int DP[MX_N * 2][MX_N][2];
bool v[MX_N][MX_N];
bool h[MX_N][MX_N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
string S[N]; REP(i, N) cin >> S[i];
FOR(i, 2, N) REP(j, M) v[i][j] = (string("") + S[i - 2][j] + S[i - 1][j] + S[i][j] == "RGW");
FOR(j, 2, M) REP(i, N) h[i][j] = (string("") + S[i][j - 2] + S[i][j - 1] + S[i][j] == "RGW");
FOE(k, 0, N + M - 2) FOR(i, 0, N) {
int j = k - i;
if (i > 0) {
DP[k][i][0] = DP[k][i - 1][0];
DP[k][i][1] = max(DP[k][i - 1][1], DP[k][i - 1][0]);
}
if (i >= 3) {
DP[k][i][0] = max(DP[k][i][0], DP[k][i - 3][1]);
}
if (j >= 0 && j < M) {
DP[k][i][0] += (int) v[i][j]; // [i][j] = end of vertical
DP[k][i][1] += (int) h[i][j]; // [i][j] = end of horizontal
}
}
int Ans = 0;
FOE(k, 0, N + M - 2)
Ans += max(DP[k][N - 1][1], DP[k][N - 1][0]);
cout << Ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
476 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
404 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
2 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
2 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Correct |
2 ms |
504 KB |
Output is correct |
43 |
Correct |
2 ms |
504 KB |
Output is correct |
44 |
Correct |
2 ms |
504 KB |
Output is correct |
45 |
Correct |
2 ms |
504 KB |
Output is correct |
46 |
Correct |
2 ms |
548 KB |
Output is correct |
47 |
Correct |
2 ms |
504 KB |
Output is correct |
48 |
Correct |
2 ms |
504 KB |
Output is correct |
49 |
Correct |
2 ms |
504 KB |
Output is correct |
50 |
Correct |
2 ms |
504 KB |
Output is correct |
51 |
Correct |
2 ms |
504 KB |
Output is correct |
52 |
Correct |
2 ms |
504 KB |
Output is correct |
53 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
476 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
404 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
2 ms |
504 KB |
Output is correct |
33 |
Correct |
3 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
504 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
2 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
504 KB |
Output is correct |
42 |
Correct |
2 ms |
504 KB |
Output is correct |
43 |
Correct |
2 ms |
504 KB |
Output is correct |
44 |
Correct |
2 ms |
504 KB |
Output is correct |
45 |
Correct |
2 ms |
504 KB |
Output is correct |
46 |
Correct |
2 ms |
548 KB |
Output is correct |
47 |
Correct |
2 ms |
504 KB |
Output is correct |
48 |
Correct |
2 ms |
504 KB |
Output is correct |
49 |
Correct |
2 ms |
504 KB |
Output is correct |
50 |
Correct |
2 ms |
504 KB |
Output is correct |
51 |
Correct |
2 ms |
504 KB |
Output is correct |
52 |
Correct |
2 ms |
504 KB |
Output is correct |
53 |
Correct |
2 ms |
504 KB |
Output is correct |
54 |
Correct |
21 ms |
12536 KB |
Output is correct |
55 |
Correct |
124 ms |
88444 KB |
Output is correct |
56 |
Correct |
13 ms |
12664 KB |
Output is correct |
57 |
Correct |
68 ms |
52984 KB |
Output is correct |
58 |
Correct |
180 ms |
31696 KB |
Output is correct |
59 |
Correct |
1726 ms |
186276 KB |
Output is correct |
60 |
Correct |
1707 ms |
186172 KB |
Output is correct |
61 |
Correct |
1717 ms |
186188 KB |
Output is correct |
62 |
Correct |
12 ms |
11768 KB |
Output is correct |
63 |
Correct |
1657 ms |
183376 KB |
Output is correct |
64 |
Correct |
1629 ms |
186340 KB |
Output is correct |
65 |
Correct |
1613 ms |
186268 KB |
Output is correct |
66 |
Correct |
1630 ms |
186172 KB |
Output is correct |
67 |
Correct |
1634 ms |
186356 KB |
Output is correct |
68 |
Correct |
1591 ms |
186204 KB |
Output is correct |
69 |
Correct |
1633 ms |
186268 KB |
Output is correct |
70 |
Correct |
162 ms |
31584 KB |
Output is correct |
71 |
Correct |
168 ms |
31656 KB |
Output is correct |
72 |
Correct |
163 ms |
31580 KB |
Output is correct |
73 |
Correct |
212 ms |
31708 KB |
Output is correct |
74 |
Correct |
164 ms |
31648 KB |
Output is correct |
75 |
Correct |
171 ms |
31636 KB |
Output is correct |
76 |
Correct |
162 ms |
31608 KB |
Output is correct |
77 |
Correct |
163 ms |
31608 KB |
Output is correct |
78 |
Correct |
164 ms |
31648 KB |
Output is correct |
79 |
Correct |
166 ms |
31680 KB |
Output is correct |
80 |
Correct |
165 ms |
31580 KB |
Output is correct |
81 |
Correct |
164 ms |
31580 KB |
Output is correct |
82 |
Correct |
165 ms |
31608 KB |
Output is correct |
83 |
Correct |
164 ms |
31664 KB |
Output is correct |
84 |
Correct |
172 ms |
31756 KB |
Output is correct |
85 |
Correct |
164 ms |
31688 KB |
Output is correct |
86 |
Correct |
167 ms |
31688 KB |
Output is correct |
87 |
Correct |
167 ms |
31596 KB |
Output is correct |
88 |
Correct |
163 ms |
31776 KB |
Output is correct |
89 |
Correct |
168 ms |
31608 KB |
Output is correct |
90 |
Correct |
164 ms |
31676 KB |
Output is correct |