This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 10;
const int MAXVAL = 6e4;
int N, M;
char A[MAXN+10][MAXN+10];
int pow3[MAXN+10], dp[MAXN+10][MAXN+10][MAXVAL+10];
int solve(int y, int x, int mask)
{
if(y==N) return 0;
int &ret=dp[y][x][mask];
if(ret!=-1) return ret;
ret=0;
if(x+1==M) ret=max(ret, solve(y+1, 0, mask/3+pow3[M-1]*(max(mask%3-1, 0))));
else ret=max(ret, solve(y, x+1, mask/3+pow3[M-1]*(max(mask%3-1, 0))));
if(A[y][x]=='R')
{
if(y+2<N && A[y][x]=='R' && A[y+1][x]=='G' && A[y+2][x]=='W' && mask%3==0)
{
if(x+1==M) ret=max(ret, solve(y+1, 0, mask/3+pow3[M-1]*2)+1);
else ret=max(ret, solve(y, x+1, mask/3+pow3[M-1]*2)+1);
}
if(x+2<M && A[y][x]=='R' && A[y][x+1]=='G' && A[y][x+2]=='W' && mask%27==0)
{
if(x+3==M) ret=max(ret, solve(y+1, 0, mask/27)+1);
else ret=max(ret, solve(y, x+3, mask/27)+1);
}
}
return ret;
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=0; i<N; i++) scanf("%s", A[i]);
pow3[0]=1;
for(i=1; i<=MAXN; i++) pow3[i]=pow3[i-1]*3;
memset(dp, -1, sizeof(dp));
printf("%d", solve(0, 0, 0));
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:45:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
dango_maker.cpp:47:10: 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:48:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=0; i<N; i++) scanf("%s", A[i]);
~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |