#include <bits/stdc++.h>
using namespace std;
const int mod= 1e9 +7;
const int N=1e5*4;
char arr[3000+5][3000+5];
void solve(){
int n,m,k;
cin>>n>>m;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>arr[i][j];
}
}
int ans = 0;
for(int j = 1;j<=m;j++){
int ind = 1,x = 1,y = j;
int dp[min(n+1,j+1)][3];
memset(dp,0ll,sizeof(dp));
while(x<=n&&y>=1){
dp[ind][0] = max({dp[ind-1][0],dp[ind-1][1],dp[ind-1][2]});
if(arr[x][y-1]=='R'&&arr[x][y]=='G'&&arr[x][y+1]=='W')dp[ind][1] = max(dp[ind-1][0],dp[ind-1][1]) + 1;
if(arr[x-1][y]=='R'&&arr[x][y]=='G'&&arr[x+1][y]=='W')dp[ind][2] = max(dp[ind-1][0],dp[ind-1][2]) + 1;
x++;y--;ind++;
}
ind--;
ans += max({dp[ind][0],dp[ind][1],dp[ind][2]});
}
for(int i = 2;i<=n;i++){
int ind = 1,x = i,y = m;
int dp[min(m+1,(n-(i-1))+1)][3];
memset(dp,0ll,sizeof(dp));
while(x<=n&&y>=1){
dp[ind][0] = max({dp[ind-1][0],dp[ind-1][1],dp[ind-1][2]});
if(arr[x][y-1]=='R'&&arr[x][y]=='G'&&arr[x][y+1]=='W')dp[ind][1] = max(dp[ind-1][0],dp[ind-1][1]) + 1;
if(arr[x-1][y]=='R'&&arr[x][y]=='G'&&arr[x+1][y]=='W')dp[ind][2] = max(dp[ind-1][0],dp[ind-1][2]) + 1;
x++;y--;ind++;
}
ind--;
ans += max({dp[ind][0],dp[ind][1],dp[ind][2]});
}
cout<<ans<<" ";
//ne spizdil , a adaptiroval
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt;
while(tt--)solve();
}
Compilation message
dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:8:10: warning: unused variable 'k' [-Wunused-variable]
8 | int n,m,k;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
416 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
416 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
600 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
416 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
600 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
344 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
1 ms |
9052 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
6748 KB |
Output is correct |
58 |
Correct |
17 ms |
5496 KB |
Output is correct |
59 |
Correct |
142 ms |
15988 KB |
Output is correct |
60 |
Correct |
144 ms |
16212 KB |
Output is correct |
61 |
Correct |
146 ms |
15976 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
135 ms |
16108 KB |
Output is correct |
64 |
Correct |
114 ms |
16212 KB |
Output is correct |
65 |
Correct |
118 ms |
15972 KB |
Output is correct |
66 |
Correct |
115 ms |
16464 KB |
Output is correct |
67 |
Correct |
116 ms |
15992 KB |
Output is correct |
68 |
Correct |
114 ms |
16112 KB |
Output is correct |
69 |
Correct |
112 ms |
16208 KB |
Output is correct |
70 |
Correct |
16 ms |
5724 KB |
Output is correct |
71 |
Correct |
14 ms |
5724 KB |
Output is correct |
72 |
Correct |
14 ms |
5724 KB |
Output is correct |
73 |
Correct |
15 ms |
5724 KB |
Output is correct |
74 |
Correct |
13 ms |
5724 KB |
Output is correct |
75 |
Correct |
14 ms |
5976 KB |
Output is correct |
76 |
Correct |
14 ms |
5724 KB |
Output is correct |
77 |
Correct |
14 ms |
5724 KB |
Output is correct |
78 |
Correct |
14 ms |
5720 KB |
Output is correct |
79 |
Correct |
14 ms |
5872 KB |
Output is correct |
80 |
Correct |
18 ms |
5724 KB |
Output is correct |
81 |
Correct |
14 ms |
5740 KB |
Output is correct |
82 |
Correct |
14 ms |
5724 KB |
Output is correct |
83 |
Correct |
13 ms |
5736 KB |
Output is correct |
84 |
Correct |
15 ms |
5724 KB |
Output is correct |
85 |
Correct |
14 ms |
5724 KB |
Output is correct |
86 |
Correct |
14 ms |
5920 KB |
Output is correct |
87 |
Correct |
14 ms |
5724 KB |
Output is correct |
88 |
Correct |
14 ms |
5724 KB |
Output is correct |
89 |
Correct |
13 ms |
5724 KB |
Output is correct |
90 |
Correct |
13 ms |
5724 KB |
Output is correct |