#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<double, double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0};
const int mxN=3100;
const int mxM=1800010;
const int mxK=104;
const ll MOD=1000000007;
const ll INF=8000000000000000001;
int N, M;
char S[mxN][mxN];
bool ok[mxN][mxN][2];
int dp[mxN][mxN][2];
int ans;
int main()
{
gibon
cin >> N >> M;
for(int i=2;i<=N+1;i++) cin >> S[i]+2;
for(int i=2;i<=N+1;i++)
{
for(int j=2;j<=M+1;j++)
{
if(S[i][j]=='R' && S[i][j+1]=='G' && S[i][j+2]=='W')
{
ok[i][j][0]=true;
}
if(S[i][j]=='R' && S[i+1][j]=='G' && S[i+2][j]=='W')
{
ok[i][j][1]=true;
}
}
}
for(int i=4;i<=N+M+2;i++)
{
for(int j=max(2, i-M-1);j<=min(i-2, N+1);j++)
{
dp[j][i-j][0]=max(dp[j-1][i-j+1][0]+ok[j][i-j][0], dp[j-2][i-j+2][1]);
dp[j][i-j][1]=max(dp[j-1][i-j+1][1]+ok[j][i-j][1], dp[j][i-j][0]);
}
ans+=dp[min(i-2, N+1)][i-min(i-2, N+1)][1];
}
cout << ans;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:28:43: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | for(int i=2;i<=N+1;i++) cin >> S[i]+2;
| ~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
300 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
412 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
324 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
324 KB |
Output is correct |
39 |
Correct |
1 ms |
312 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
320 KB |
Output is correct |
49 |
Correct |
1 ms |
312 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
328 KB |
Output is correct |
53 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
300 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
412 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
324 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
324 KB |
Output is correct |
39 |
Correct |
1 ms |
312 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
320 KB |
Output is correct |
49 |
Correct |
1 ms |
312 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
328 KB |
Output is correct |
53 |
Correct |
1 ms |
324 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
12 ms |
21984 KB |
Output is correct |
56 |
Correct |
2 ms |
464 KB |
Output is correct |
57 |
Correct |
11 ms |
21572 KB |
Output is correct |
58 |
Correct |
28 ms |
22112 KB |
Output is correct |
59 |
Correct |
293 ms |
109128 KB |
Output is correct |
60 |
Correct |
270 ms |
109168 KB |
Output is correct |
61 |
Correct |
295 ms |
109188 KB |
Output is correct |
62 |
Correct |
1 ms |
320 KB |
Output is correct |
63 |
Correct |
309 ms |
108816 KB |
Output is correct |
64 |
Correct |
242 ms |
109180 KB |
Output is correct |
65 |
Correct |
214 ms |
109236 KB |
Output is correct |
66 |
Correct |
222 ms |
109204 KB |
Output is correct |
67 |
Correct |
200 ms |
100912 KB |
Output is correct |
68 |
Correct |
204 ms |
100956 KB |
Output is correct |
69 |
Correct |
223 ms |
104876 KB |
Output is correct |
70 |
Correct |
27 ms |
22256 KB |
Output is correct |
71 |
Correct |
24 ms |
22084 KB |
Output is correct |
72 |
Correct |
20 ms |
22100 KB |
Output is correct |
73 |
Correct |
21 ms |
22072 KB |
Output is correct |
74 |
Correct |
22 ms |
22048 KB |
Output is correct |
75 |
Correct |
19 ms |
22088 KB |
Output is correct |
76 |
Correct |
18 ms |
22060 KB |
Output is correct |
77 |
Correct |
23 ms |
22080 KB |
Output is correct |
78 |
Correct |
22 ms |
22040 KB |
Output is correct |
79 |
Correct |
22 ms |
22088 KB |
Output is correct |
80 |
Correct |
22 ms |
22032 KB |
Output is correct |
81 |
Correct |
21 ms |
22092 KB |
Output is correct |
82 |
Correct |
22 ms |
22052 KB |
Output is correct |
83 |
Correct |
20 ms |
22124 KB |
Output is correct |
84 |
Correct |
20 ms |
22040 KB |
Output is correct |
85 |
Correct |
22 ms |
22244 KB |
Output is correct |
86 |
Correct |
27 ms |
22076 KB |
Output is correct |
87 |
Correct |
30 ms |
22088 KB |
Output is correct |
88 |
Correct |
30 ms |
22092 KB |
Output is correct |
89 |
Correct |
28 ms |
22068 KB |
Output is correct |
90 |
Correct |
28 ms |
22088 KB |
Output is correct |