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 H[N][N][2],m,n,i,j,ans,nn,z;
char A[N][N];
void f(int x, int y, int h){
if(H[x][y][h]) return;
H[x][y][h] = 1;
nn++;
z += h;
if(h){
if(y <= n-2 && A[x][y+1] == 'G' && A[x][y+2] == 'W') f(x,y,!h);
if(y >= 2 && y <= n-1 && A[x+1][y-1] == 'R' && A[x+1][y+1] == 'W') f(x+1,y-1,!h);
if(y >= 3 && A[x+2][y-2] == 'R' && A[x+2][y-1] == 'G') f(x+2,y-2,!h);
}
else{
if(x <= m-2 && A[x+1][y] == 'G' && A[x+2][y] == 'W') f(x,y,!h);
if(x <= m-1 && x >= 2 && A[x-1][y+1] == 'R' && A[x+1][y+1] == 'W') f(x-1,y+1,!h);
if(x >= 3 && A[x-2][y+2] == 'R' && A[x-1][y+2] == 'G') f(x-2,y+2,!h);
}
}
int main(){
scanf("%d%d",&m,&n);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf(" %c", &A[i][j]);
for(i=1;i<=m;i++)
for(j=1;j<=n-2;j++){
if(A[i][j] == 'R' && A[i][j+1] == 'G' && A[i][j+2] == 'W'){
nn = z = 0;
f(i,j,0);
ans += max(z , nn-z);
}
}
for(i=1;i<=m-2;i++)
for(j=1;j<=n;j++){
if(A[i][j] == 'R' && A[i+1][j] == 'G' && A[i+2][j] == 'W'){
nn = z = 0;
f(i,j,1);
ans += max(z , nn-z);
}
}
printf("%d",ans);
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:36: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:39: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... |