#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int n,m;
ii arr[3000][3000];
char arr1[3000][3000];
int dp[3001][2][2];
int cal(int i,int j,int k,int l,int c)
{
if(dp[i][k][l]!=-1)
return(dp[i][k][l]);
dp[i][k][l]=0;
if(i==n||j==m)
return(0);
int ans=0;
ans=cal(i+1,j+1,0,k,c+1);
if(arr[i][j].F==1)
ans=max(ans,1+cal(i+1,j+1,1,k,c+1));
if(arr[i][j].S==1&&k!=1&&l!=1)
ans=max(ans,1+cal(i+1,j+1,2,k,c+1));
dp[i][k][l]=ans;
return(dp[i][k][l]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=n-1;i>=0;--i)
for(int j=0;j<m;++j)
cin>>arr1[i][j];
for(int i=0;i<n;++i)
{
for(int j=0;j<m;++j)
{
arr[i][j]=mp(0,0);
if(i>1&&arr1[i][j]=='R'&&arr1[i-1][j]=='G'&&arr1[i-2][j]=='W')
arr[i][j].S=1;
if(j+2<m&&arr1[i][j]=='R'&&arr1[i][j+1]=='G'&&arr1[i][j+2]=='W')
arr[i][j].F=1;
}
}
int ans=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
for(int k=0;k<3;++k)
for(int l=0;l<3;++l)
dp[j][k][l]=-1;
ans+=cal(i,0,0,0,0);
}
for(int j=1;j<m;++j)
{
for(int i=0;i<n;++i)
for(int k=0;k<3;++k)
for(int l=0;l<3;++l)
dp[i][k][l]=-1;
ans+=cal(0,j,0,0,0);
}
cout<<ans<<endl;
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:62:22: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
dp[j][k][l]=-1;
~~~~~~~~~~~^~~
dango_maker.cpp:61:22: note: within this loop
for(int l=0;l<3;++l)
~^~
dango_maker.cpp:70:22: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
dp[i][k][l]=-1;
~~~~~~~~~~~^~~
dango_maker.cpp:69:22: note: within this loop
for(int l=0;l<3;++l)
~^~
dango_maker.cpp:70:22: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
dp[i][k][l]=-1;
~~~~~~~~~~~^~~
dango_maker.cpp:68:20: note: within this loop
for(int k=0;k<3;++k)
~^~
dango_maker.cpp:62:22: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
dp[j][k][l]=-1;
~~~~~~~~~~~^~~
dango_maker.cpp:60:20: note: within this loop
for(int k=0;k<3;++k)
~^~
dango_maker.cpp:62:21: warning: array subscript is above array bounds [-Warray-bounds]
dp[j][k][l]=-1;
~~~~~~~~~~^
dango_maker.cpp:62:21: warning: array subscript is above array bounds [-Warray-bounds]
dango_maker.cpp:62:18: warning: array subscript is above array bounds [-Warray-bounds]
dp[j][k][l]=-1;
~~~~~~~^
dango_maker.cpp:62:21: warning: array subscript is above array bounds [-Warray-bounds]
dp[j][k][l]=-1;
~~~~~~~~~~^
dango_maker.cpp:62:18: warning: array subscript is above array bounds [-Warray-bounds]
dp[j][k][l]=-1;
~~~~~~~^
dango_maker.cpp:70:21: warning: array subscript is above array bounds [-Warray-bounds]
dp[i][k][l]=-1;
~~~~~~~~~~^
dango_maker.cpp:70:21: warning: array subscript is above array bounds [-Warray-bounds]
dango_maker.cpp:70:18: warning: array subscript is above array bounds [-Warray-bounds]
dp[i][k][l]=-1;
~~~~~~~^
dango_maker.cpp:70:21: warning: array subscript is above array bounds [-Warray-bounds]
dp[i][k][l]=-1;
~~~~~~~~~~^
dango_maker.cpp:70:18: warning: array subscript is above array bounds [-Warray-bounds]
dp[i][k][l]=-1;
~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |