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;
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N = 3e3 + 3;
int M[N][N][2][2],H[N][N],m,n,i,j,ans;
char A[N][N];
int f(int x, int y, int a, int b){
if(A[x][y] != 'G') return 0;
H[x][y] = 1;
int &r = M[x][y][a][b];
if(r != -1) return r;
if(a && A[x][y-1] == 'R') r = max(r , f(x+1,y-1,A[x+1][y]=='W',0)+1);
if(b && A[x+1][y] == 'W') r = max(r , f(x+1,y-1,0,A[x][y-1]=='R')+1);
return r = max(r , f(x+1,y-1,A[x+1][y]=='W',A[x][y-1]=='R'));
}
int main(){
scanf("%d%d",&m,&n);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf(" %c", &A[i][j]);
memset(M , -1 , sizeof M);
for(i=1;i<=m;i++)
for(j=n; j ;j--)
if(A[i][j] == 'G' && !H[i][j])
ans += f(i,j,A[i][j+1]=='W',A[i-1][j]=='R');
printf("%d",ans);
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&m,&n);
~~~~~^~~~~~~~~~~~~~
dango_maker.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &A[i][j]);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |