#include <iostream>
#include <string.h>
using namespace std;
int dp[5005][3][3],n,m;
char arr[5005][5005];
int solve(int i,int x,int y,int a,int b)
{
if (!x || y>m)
return 0;
if (dp[i][a][b]!=-1)
return dp[i][a][b];
int ans=solve(i+1,x-1,y+1,0,a);
if (arr[x][y]=='R')
{
if (arr[x][y+1]=='G' && arr[x][y+2]=='W')
ans=max(ans,solve(i+1,x-1,y+1,1,a)+1);
if (arr[x+1][y]=='G' && arr[x+2][y]=='W' && a!=1 && b!=1)
ans=max(ans,solve(i+1,x-1,y+1,2,a)+1);
}
return dp[i][a][b]=ans;
}
int main()
{
int ans=0;
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
scanf(" %c",&arr[i][j]);
}
for (int i=1;i<n+m;i++)
{
memset(dp,-1,sizeof(dp));
ans+=solve(0,min(i,n),max(1,i-n+1),0,0);
}
printf("%d",ans);
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:25: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:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&arr[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
3 ms |
592 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
540 KB |
Output is correct |
33 |
Correct |
2 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
4 ms |
512 KB |
Output is correct |
36 |
Correct |
2 ms |
536 KB |
Output is correct |
37 |
Correct |
2 ms |
496 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
3 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
3 ms |
512 KB |
Output is correct |
48 |
Correct |
3 ms |
512 KB |
Output is correct |
49 |
Correct |
2 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
3 ms |
512 KB |
Output is correct |
53 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
3 ms |
592 KB |
Output is correct |
31 |
Correct |
4 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
540 KB |
Output is correct |
33 |
Correct |
2 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
4 ms |
512 KB |
Output is correct |
36 |
Correct |
2 ms |
536 KB |
Output is correct |
37 |
Correct |
2 ms |
496 KB |
Output is correct |
38 |
Correct |
2 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
512 KB |
Output is correct |
43 |
Correct |
2 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
3 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
3 ms |
512 KB |
Output is correct |
48 |
Correct |
3 ms |
512 KB |
Output is correct |
49 |
Correct |
2 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
2 ms |
512 KB |
Output is correct |
52 |
Correct |
3 ms |
512 KB |
Output is correct |
53 |
Correct |
2 ms |
512 KB |
Output is correct |
54 |
Correct |
26 ms |
512 KB |
Output is correct |
55 |
Correct |
37 ms |
12544 KB |
Output is correct |
56 |
Correct |
29 ms |
632 KB |
Output is correct |
57 |
Correct |
26 ms |
8576 KB |
Output is correct |
58 |
Correct |
106 ms |
6740 KB |
Output is correct |
59 |
Correct |
897 ms |
24344 KB |
Output is correct |
60 |
Correct |
795 ms |
24392 KB |
Output is correct |
61 |
Correct |
883 ms |
24312 KB |
Output is correct |
62 |
Correct |
27 ms |
512 KB |
Output is correct |
63 |
Correct |
807 ms |
24188 KB |
Output is correct |
64 |
Correct |
1076 ms |
24416 KB |
Output is correct |
65 |
Correct |
1202 ms |
24448 KB |
Output is correct |
66 |
Correct |
1154 ms |
24496 KB |
Output is correct |
67 |
Correct |
937 ms |
24548 KB |
Output is correct |
68 |
Correct |
802 ms |
24312 KB |
Output is correct |
69 |
Correct |
777 ms |
24312 KB |
Output is correct |
70 |
Correct |
120 ms |
6520 KB |
Output is correct |
71 |
Correct |
134 ms |
6500 KB |
Output is correct |
72 |
Correct |
137 ms |
6520 KB |
Output is correct |
73 |
Correct |
133 ms |
6520 KB |
Output is correct |
74 |
Correct |
130 ms |
6492 KB |
Output is correct |
75 |
Correct |
132 ms |
6600 KB |
Output is correct |
76 |
Correct |
142 ms |
6448 KB |
Output is correct |
77 |
Correct |
129 ms |
6460 KB |
Output is correct |
78 |
Correct |
129 ms |
6520 KB |
Output is correct |
79 |
Correct |
124 ms |
6456 KB |
Output is correct |
80 |
Correct |
122 ms |
6520 KB |
Output is correct |
81 |
Correct |
120 ms |
6520 KB |
Output is correct |
82 |
Correct |
159 ms |
6436 KB |
Output is correct |
83 |
Correct |
127 ms |
6520 KB |
Output is correct |
84 |
Correct |
135 ms |
6520 KB |
Output is correct |
85 |
Correct |
154 ms |
6520 KB |
Output is correct |
86 |
Correct |
141 ms |
6432 KB |
Output is correct |
87 |
Correct |
228 ms |
6572 KB |
Output is correct |
88 |
Correct |
137 ms |
6520 KB |
Output is correct |
89 |
Correct |
122 ms |
6456 KB |
Output is correct |
90 |
Correct |
171 ms |
6520 KB |
Output is correct |