#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
int n, m;
char s[3010][3010];
int dp[6010][3010][2];
bool is(int i, int j, char c){
return 1<=i && i<=n && 1<=j && j<=m && s[i][j] == c;
}
int main()
{
read(n, m);
for(int i=1; i<=n; ++i) scanf("%s", s[i]+1);
int ans = 0;
for(int s=2; s<=n+m-2; ++s){
int rm=0;
for(int i=1; i<=n; ++i){
dp[s][i][0] = max({dp[s][i][0], dp[s][i-1][0], dp[s][i-2][1]});
dp[s][i][1] = max(dp[s][i][1], dp[s][i-1][1]);
int j=s-i;
if(j<1 || j>m) continue;
if(is(i, j, 'R') && is(i, j+1, 'G') && is(i, j+2, 'W')){
dp[s][i][0] = max(dp[s][i][0], dp[s][i-1][0]+1);
}
if(is(i, j, 'R') && is(i+1, j, 'G') && is(i+2, j, 'W')){
dp[s][i][1] = max({dp[s][i][1], dp[s][i-1][1]+1, dp[s][i-1][0]+1});
}
rm=max({rm, dp[s][i][0], dp[s][i][1]});
}
//if(rm) printf("%d: rm %d\n", s, rm);
ans += rm;
}
printf("%d\n", ans);
return 0;
}
Compilation message
dango_maker.cpp: In function 'void read(int&)':
dango_maker.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
void read(int& x){ scanf("%d",&x); }
~~~~~^~~~~~~~~
dango_maker.cpp: In function 'void read(ll&)':
dango_maker.cpp:7:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
void read(ll& x){ scanf("%lld",&x); }
~~~~~^~~~~~~~~~~
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:28:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=n; ++i) scanf("%s", s[i]+1);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
516 KB |
Output is correct |
5 |
Correct |
3 ms |
568 KB |
Output is correct |
6 |
Correct |
3 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
664 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
784 KB |
Output is correct |
14 |
Correct |
2 ms |
788 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
516 KB |
Output is correct |
5 |
Correct |
3 ms |
568 KB |
Output is correct |
6 |
Correct |
3 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
664 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
784 KB |
Output is correct |
14 |
Correct |
2 ms |
788 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
796 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
3 ms |
812 KB |
Output is correct |
21 |
Correct |
2 ms |
820 KB |
Output is correct |
22 |
Correct |
2 ms |
820 KB |
Output is correct |
23 |
Correct |
2 ms |
824 KB |
Output is correct |
24 |
Correct |
3 ms |
844 KB |
Output is correct |
25 |
Correct |
3 ms |
864 KB |
Output is correct |
26 |
Correct |
2 ms |
864 KB |
Output is correct |
27 |
Correct |
3 ms |
928 KB |
Output is correct |
28 |
Correct |
2 ms |
928 KB |
Output is correct |
29 |
Correct |
2 ms |
928 KB |
Output is correct |
30 |
Correct |
2 ms |
928 KB |
Output is correct |
31 |
Correct |
3 ms |
928 KB |
Output is correct |
32 |
Correct |
3 ms |
928 KB |
Output is correct |
33 |
Correct |
3 ms |
928 KB |
Output is correct |
34 |
Correct |
4 ms |
928 KB |
Output is correct |
35 |
Correct |
2 ms |
928 KB |
Output is correct |
36 |
Correct |
3 ms |
928 KB |
Output is correct |
37 |
Correct |
2 ms |
928 KB |
Output is correct |
38 |
Correct |
3 ms |
928 KB |
Output is correct |
39 |
Correct |
3 ms |
928 KB |
Output is correct |
40 |
Correct |
3 ms |
928 KB |
Output is correct |
41 |
Correct |
3 ms |
928 KB |
Output is correct |
42 |
Correct |
2 ms |
928 KB |
Output is correct |
43 |
Correct |
2 ms |
928 KB |
Output is correct |
44 |
Correct |
2 ms |
928 KB |
Output is correct |
45 |
Correct |
2 ms |
928 KB |
Output is correct |
46 |
Correct |
3 ms |
928 KB |
Output is correct |
47 |
Correct |
2 ms |
928 KB |
Output is correct |
48 |
Correct |
2 ms |
928 KB |
Output is correct |
49 |
Correct |
3 ms |
928 KB |
Output is correct |
50 |
Correct |
3 ms |
932 KB |
Output is correct |
51 |
Correct |
2 ms |
936 KB |
Output is correct |
52 |
Correct |
4 ms |
960 KB |
Output is correct |
53 |
Correct |
2 ms |
960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
516 KB |
Output is correct |
5 |
Correct |
3 ms |
568 KB |
Output is correct |
6 |
Correct |
3 ms |
664 KB |
Output is correct |
7 |
Correct |
2 ms |
664 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
768 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
784 KB |
Output is correct |
14 |
Correct |
2 ms |
788 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
796 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
3 ms |
812 KB |
Output is correct |
21 |
Correct |
2 ms |
820 KB |
Output is correct |
22 |
Correct |
2 ms |
820 KB |
Output is correct |
23 |
Correct |
2 ms |
824 KB |
Output is correct |
24 |
Correct |
3 ms |
844 KB |
Output is correct |
25 |
Correct |
3 ms |
864 KB |
Output is correct |
26 |
Correct |
2 ms |
864 KB |
Output is correct |
27 |
Correct |
3 ms |
928 KB |
Output is correct |
28 |
Correct |
2 ms |
928 KB |
Output is correct |
29 |
Correct |
2 ms |
928 KB |
Output is correct |
30 |
Correct |
2 ms |
928 KB |
Output is correct |
31 |
Correct |
3 ms |
928 KB |
Output is correct |
32 |
Correct |
3 ms |
928 KB |
Output is correct |
33 |
Correct |
3 ms |
928 KB |
Output is correct |
34 |
Correct |
4 ms |
928 KB |
Output is correct |
35 |
Correct |
2 ms |
928 KB |
Output is correct |
36 |
Correct |
3 ms |
928 KB |
Output is correct |
37 |
Correct |
2 ms |
928 KB |
Output is correct |
38 |
Correct |
3 ms |
928 KB |
Output is correct |
39 |
Correct |
3 ms |
928 KB |
Output is correct |
40 |
Correct |
3 ms |
928 KB |
Output is correct |
41 |
Correct |
3 ms |
928 KB |
Output is correct |
42 |
Correct |
2 ms |
928 KB |
Output is correct |
43 |
Correct |
2 ms |
928 KB |
Output is correct |
44 |
Correct |
2 ms |
928 KB |
Output is correct |
45 |
Correct |
2 ms |
928 KB |
Output is correct |
46 |
Correct |
3 ms |
928 KB |
Output is correct |
47 |
Correct |
2 ms |
928 KB |
Output is correct |
48 |
Correct |
2 ms |
928 KB |
Output is correct |
49 |
Correct |
3 ms |
928 KB |
Output is correct |
50 |
Correct |
3 ms |
932 KB |
Output is correct |
51 |
Correct |
2 ms |
936 KB |
Output is correct |
52 |
Correct |
4 ms |
960 KB |
Output is correct |
53 |
Correct |
2 ms |
960 KB |
Output is correct |
54 |
Correct |
17 ms |
12980 KB |
Output is correct |
55 |
Correct |
117 ms |
80360 KB |
Output is correct |
56 |
Correct |
15 ms |
80360 KB |
Output is correct |
57 |
Correct |
62 ms |
80360 KB |
Output is correct |
58 |
Correct |
59 ms |
80360 KB |
Output is correct |
59 |
Correct |
380 ms |
161112 KB |
Output is correct |
60 |
Correct |
363 ms |
169800 KB |
Output is correct |
61 |
Correct |
365 ms |
178500 KB |
Output is correct |
62 |
Correct |
16 ms |
178500 KB |
Output is correct |
63 |
Correct |
363 ms |
184860 KB |
Output is correct |
64 |
Correct |
314 ms |
195952 KB |
Output is correct |
65 |
Correct |
294 ms |
204792 KB |
Output is correct |
66 |
Correct |
335 ms |
213476 KB |
Output is correct |
67 |
Correct |
330 ms |
222440 KB |
Output is correct |
68 |
Correct |
348 ms |
231196 KB |
Output is correct |
69 |
Correct |
338 ms |
239944 KB |
Output is correct |
70 |
Correct |
49 ms |
239944 KB |
Output is correct |
71 |
Correct |
47 ms |
239944 KB |
Output is correct |
72 |
Correct |
49 ms |
239944 KB |
Output is correct |
73 |
Correct |
47 ms |
239944 KB |
Output is correct |
74 |
Correct |
57 ms |
239944 KB |
Output is correct |
75 |
Correct |
58 ms |
239944 KB |
Output is correct |
76 |
Correct |
59 ms |
239944 KB |
Output is correct |
77 |
Correct |
42 ms |
239944 KB |
Output is correct |
78 |
Correct |
42 ms |
239944 KB |
Output is correct |
79 |
Correct |
43 ms |
239944 KB |
Output is correct |
80 |
Correct |
50 ms |
239944 KB |
Output is correct |
81 |
Correct |
51 ms |
239944 KB |
Output is correct |
82 |
Correct |
48 ms |
239944 KB |
Output is correct |
83 |
Correct |
50 ms |
239944 KB |
Output is correct |
84 |
Correct |
48 ms |
239944 KB |
Output is correct |
85 |
Correct |
46 ms |
239944 KB |
Output is correct |
86 |
Correct |
49 ms |
239944 KB |
Output is correct |
87 |
Correct |
44 ms |
239944 KB |
Output is correct |
88 |
Correct |
46 ms |
239944 KB |
Output is correct |
89 |
Correct |
59 ms |
239944 KB |
Output is correct |
90 |
Correct |
62 ms |
239944 KB |
Output is correct |