/*
Idea:
- http://codeforces.com/blog/entry/57637?#comment-413356 (Problem 3)
*/
// debug 12.18
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1 << 30)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 3111
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
char str[maxn][maxn];
int dp[maxn][maxn][3];
int n, m;
bool can(int x, int y, char c){
if(x < 1 || x > n || y < 1 || y > m)
return 0;
return (str[x][y] == c);
}
int fun(int x, int y, int t){ // 0 - nothing, 1 - horizontal, 2 - vertical
if(x < 1 || x > n || y < 1 || y > m)
return 0;
int &cur = dp[x][y][t];
if(cur != -1)
return cur;
int add = 0;
if(t == 1 && can(x, y - 1, 'R') && can(x, y, 'G') && can(x, y + 1, 'W'))
add = 1;
if(t == 2 && can(x - 1, y, 'R') && can(x, y, 'G') && can(x + 1, y, 'W'))
add = 1;
cur = 0;
if(t != 0 && add == 0)
return cur;
for(int i = 0; i < 3; i++){
if(t + i == 3)
continue;
cur = max(cur, fun(x - 1, y + 1, i) + add);
}
return cur;
}
int main(){
scanf("%d%d", &n, &m);
memset(dp, -1, sizeof(dp));
for(int i = 1; i <= n; i++)
scanf("%s", str[i] + 1);
int ans = 0;
for(int i = 1; i <= n; i++){
int tren = max(fun(i, 1, 0), max(fun(i, 1, 1), fun(i, 1, 2)));
ans += tren;
// cout << i << " 1:" << tren << endl;
}
for(int i = 2; i <= m; i++){
ans += max(fun(n, i, 0), max(fun(n, i, 1), fun(n, i, 2)));
// cout << i << " 1:" << tren << endl;
}
printf("%d\n", ans);
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:64: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:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", str[i] + 1);
~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
113912 KB |
Output is correct |
2 |
Correct |
95 ms |
113972 KB |
Output is correct |
3 |
Correct |
94 ms |
114224 KB |
Output is correct |
4 |
Correct |
85 ms |
114224 KB |
Output is correct |
5 |
Correct |
97 ms |
114224 KB |
Output is correct |
6 |
Correct |
99 ms |
114280 KB |
Output is correct |
7 |
Correct |
99 ms |
114280 KB |
Output is correct |
8 |
Correct |
97 ms |
114280 KB |
Output is correct |
9 |
Correct |
104 ms |
114452 KB |
Output is correct |
10 |
Correct |
95 ms |
114452 KB |
Output is correct |
11 |
Correct |
93 ms |
114452 KB |
Output is correct |
12 |
Correct |
87 ms |
114452 KB |
Output is correct |
13 |
Correct |
98 ms |
114452 KB |
Output is correct |
14 |
Correct |
105 ms |
114452 KB |
Output is correct |
15 |
Correct |
90 ms |
114452 KB |
Output is correct |
16 |
Correct |
92 ms |
114452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
113912 KB |
Output is correct |
2 |
Correct |
95 ms |
113972 KB |
Output is correct |
3 |
Correct |
94 ms |
114224 KB |
Output is correct |
4 |
Correct |
85 ms |
114224 KB |
Output is correct |
5 |
Correct |
97 ms |
114224 KB |
Output is correct |
6 |
Correct |
99 ms |
114280 KB |
Output is correct |
7 |
Correct |
99 ms |
114280 KB |
Output is correct |
8 |
Correct |
97 ms |
114280 KB |
Output is correct |
9 |
Correct |
104 ms |
114452 KB |
Output is correct |
10 |
Correct |
95 ms |
114452 KB |
Output is correct |
11 |
Correct |
93 ms |
114452 KB |
Output is correct |
12 |
Correct |
87 ms |
114452 KB |
Output is correct |
13 |
Correct |
98 ms |
114452 KB |
Output is correct |
14 |
Correct |
105 ms |
114452 KB |
Output is correct |
15 |
Correct |
90 ms |
114452 KB |
Output is correct |
16 |
Correct |
92 ms |
114452 KB |
Output is correct |
17 |
Correct |
92 ms |
114452 KB |
Output is correct |
18 |
Correct |
97 ms |
114452 KB |
Output is correct |
19 |
Correct |
100 ms |
114452 KB |
Output is correct |
20 |
Correct |
98 ms |
114452 KB |
Output is correct |
21 |
Correct |
93 ms |
114452 KB |
Output is correct |
22 |
Correct |
103 ms |
114452 KB |
Output is correct |
23 |
Correct |
98 ms |
114452 KB |
Output is correct |
24 |
Correct |
100 ms |
114452 KB |
Output is correct |
25 |
Correct |
93 ms |
114452 KB |
Output is correct |
26 |
Correct |
86 ms |
114452 KB |
Output is correct |
27 |
Correct |
97 ms |
114452 KB |
Output is correct |
28 |
Correct |
97 ms |
114452 KB |
Output is correct |
29 |
Correct |
95 ms |
114452 KB |
Output is correct |
30 |
Correct |
92 ms |
114452 KB |
Output is correct |
31 |
Correct |
95 ms |
114452 KB |
Output is correct |
32 |
Correct |
94 ms |
114452 KB |
Output is correct |
33 |
Correct |
91 ms |
114452 KB |
Output is correct |
34 |
Correct |
93 ms |
114452 KB |
Output is correct |
35 |
Correct |
94 ms |
114452 KB |
Output is correct |
36 |
Correct |
94 ms |
114452 KB |
Output is correct |
37 |
Correct |
91 ms |
114452 KB |
Output is correct |
38 |
Correct |
93 ms |
114452 KB |
Output is correct |
39 |
Correct |
100 ms |
114452 KB |
Output is correct |
40 |
Correct |
87 ms |
114452 KB |
Output is correct |
41 |
Correct |
95 ms |
114452 KB |
Output is correct |
42 |
Correct |
88 ms |
114452 KB |
Output is correct |
43 |
Correct |
84 ms |
114452 KB |
Output is correct |
44 |
Correct |
93 ms |
114452 KB |
Output is correct |
45 |
Correct |
84 ms |
114452 KB |
Output is correct |
46 |
Correct |
96 ms |
114452 KB |
Output is correct |
47 |
Correct |
107 ms |
114452 KB |
Output is correct |
48 |
Correct |
86 ms |
114452 KB |
Output is correct |
49 |
Correct |
87 ms |
114452 KB |
Output is correct |
50 |
Correct |
89 ms |
114452 KB |
Output is correct |
51 |
Correct |
101 ms |
114452 KB |
Output is correct |
52 |
Correct |
86 ms |
114452 KB |
Output is correct |
53 |
Correct |
101 ms |
114452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
113912 KB |
Output is correct |
2 |
Correct |
95 ms |
113972 KB |
Output is correct |
3 |
Correct |
94 ms |
114224 KB |
Output is correct |
4 |
Correct |
85 ms |
114224 KB |
Output is correct |
5 |
Correct |
97 ms |
114224 KB |
Output is correct |
6 |
Correct |
99 ms |
114280 KB |
Output is correct |
7 |
Correct |
99 ms |
114280 KB |
Output is correct |
8 |
Correct |
97 ms |
114280 KB |
Output is correct |
9 |
Correct |
104 ms |
114452 KB |
Output is correct |
10 |
Correct |
95 ms |
114452 KB |
Output is correct |
11 |
Correct |
93 ms |
114452 KB |
Output is correct |
12 |
Correct |
87 ms |
114452 KB |
Output is correct |
13 |
Correct |
98 ms |
114452 KB |
Output is correct |
14 |
Correct |
105 ms |
114452 KB |
Output is correct |
15 |
Correct |
90 ms |
114452 KB |
Output is correct |
16 |
Correct |
92 ms |
114452 KB |
Output is correct |
17 |
Correct |
92 ms |
114452 KB |
Output is correct |
18 |
Correct |
97 ms |
114452 KB |
Output is correct |
19 |
Correct |
100 ms |
114452 KB |
Output is correct |
20 |
Correct |
98 ms |
114452 KB |
Output is correct |
21 |
Correct |
93 ms |
114452 KB |
Output is correct |
22 |
Correct |
103 ms |
114452 KB |
Output is correct |
23 |
Correct |
98 ms |
114452 KB |
Output is correct |
24 |
Correct |
100 ms |
114452 KB |
Output is correct |
25 |
Correct |
93 ms |
114452 KB |
Output is correct |
26 |
Correct |
86 ms |
114452 KB |
Output is correct |
27 |
Correct |
97 ms |
114452 KB |
Output is correct |
28 |
Correct |
97 ms |
114452 KB |
Output is correct |
29 |
Correct |
95 ms |
114452 KB |
Output is correct |
30 |
Correct |
92 ms |
114452 KB |
Output is correct |
31 |
Correct |
95 ms |
114452 KB |
Output is correct |
32 |
Correct |
94 ms |
114452 KB |
Output is correct |
33 |
Correct |
91 ms |
114452 KB |
Output is correct |
34 |
Correct |
93 ms |
114452 KB |
Output is correct |
35 |
Correct |
94 ms |
114452 KB |
Output is correct |
36 |
Correct |
94 ms |
114452 KB |
Output is correct |
37 |
Correct |
91 ms |
114452 KB |
Output is correct |
38 |
Correct |
93 ms |
114452 KB |
Output is correct |
39 |
Correct |
100 ms |
114452 KB |
Output is correct |
40 |
Correct |
87 ms |
114452 KB |
Output is correct |
41 |
Correct |
95 ms |
114452 KB |
Output is correct |
42 |
Correct |
88 ms |
114452 KB |
Output is correct |
43 |
Correct |
84 ms |
114452 KB |
Output is correct |
44 |
Correct |
93 ms |
114452 KB |
Output is correct |
45 |
Correct |
84 ms |
114452 KB |
Output is correct |
46 |
Correct |
96 ms |
114452 KB |
Output is correct |
47 |
Correct |
107 ms |
114452 KB |
Output is correct |
48 |
Correct |
86 ms |
114452 KB |
Output is correct |
49 |
Correct |
87 ms |
114452 KB |
Output is correct |
50 |
Correct |
89 ms |
114452 KB |
Output is correct |
51 |
Correct |
101 ms |
114452 KB |
Output is correct |
52 |
Correct |
86 ms |
114452 KB |
Output is correct |
53 |
Correct |
101 ms |
114452 KB |
Output is correct |
54 |
Correct |
90 ms |
114452 KB |
Output is correct |
55 |
Correct |
105 ms |
123388 KB |
Output is correct |
56 |
Correct |
104 ms |
123388 KB |
Output is correct |
57 |
Correct |
104 ms |
123388 KB |
Output is correct |
58 |
Correct |
192 ms |
123388 KB |
Output is correct |
59 |
Correct |
1197 ms |
123644 KB |
Output is correct |
60 |
Correct |
1076 ms |
132604 KB |
Output is correct |
61 |
Correct |
1061 ms |
141304 KB |
Output is correct |
62 |
Correct |
96 ms |
141304 KB |
Output is correct |
63 |
Correct |
1141 ms |
149928 KB |
Output is correct |
64 |
Correct |
1130 ms |
158764 KB |
Output is correct |
65 |
Correct |
1072 ms |
167612 KB |
Output is correct |
66 |
Correct |
1177 ms |
176312 KB |
Output is correct |
67 |
Correct |
1145 ms |
185144 KB |
Output is correct |
68 |
Correct |
1077 ms |
193996 KB |
Output is correct |
69 |
Correct |
999 ms |
202864 KB |
Output is correct |
70 |
Correct |
163 ms |
202864 KB |
Output is correct |
71 |
Correct |
188 ms |
202864 KB |
Output is correct |
72 |
Correct |
197 ms |
202864 KB |
Output is correct |
73 |
Correct |
157 ms |
202864 KB |
Output is correct |
74 |
Correct |
170 ms |
202864 KB |
Output is correct |
75 |
Correct |
153 ms |
202864 KB |
Output is correct |
76 |
Correct |
229 ms |
203380 KB |
Output is correct |
77 |
Correct |
199 ms |
204480 KB |
Output is correct |
78 |
Correct |
178 ms |
205376 KB |
Output is correct |
79 |
Correct |
186 ms |
206296 KB |
Output is correct |
80 |
Correct |
203 ms |
207252 KB |
Output is correct |
81 |
Correct |
202 ms |
208380 KB |
Output is correct |
82 |
Correct |
164 ms |
209284 KB |
Output is correct |
83 |
Correct |
160 ms |
210140 KB |
Output is correct |
84 |
Correct |
165 ms |
211312 KB |
Output is correct |
85 |
Correct |
214 ms |
212220 KB |
Output is correct |
86 |
Correct |
198 ms |
213224 KB |
Output is correct |
87 |
Correct |
189 ms |
214276 KB |
Output is correct |
88 |
Correct |
183 ms |
215120 KB |
Output is correct |
89 |
Correct |
181 ms |
216088 KB |
Output is correct |
90 |
Correct |
177 ms |
217016 KB |
Output is correct |