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;
// TASQUE C
int n,m,a[3001][3001],ans=0;
/*void display() {
for(int i=0; i<=n+1; i++) {
for(int j=0; j<=m+1; j++)
cout<<a[i][j]<<' ';
cout<<'\n';
}
cout<<'\n';
}*/
int c(int x,int y,int d,int p,int ol=0) {
if(a[x][y]!=p+1)
return -1;
/*cout<<"\n at point "<<x<<y<<" im "<<a[x][y]<<" and parent is "<<p<<d<<" ALSOO "<<ol<<'\n';
cout<<'\n'<<ol<<'\n'<<(a[x-1][y]==2)<<'\n'<<(a[max(0,x-2)][y]==1)<<'\n';*/
if(!p) {
int h=c(x,y+1,1,1);
int v=c(x+1,y,2,1);
if(h==-1 && v==-1)
return 0;
if(h!=-1 && v!=-1) {
if(h<=v) {
a[x][y]=0;
a[x][y+1]=0;
a[x][y+2]=0;
ans++;
}
else {
a[x][y]=0;
a[x+1][y]=0;
a[x+2][y]=0;
ans++;
}
}
else if(h!=-1 && v==-1) {
a[x][y]=0;
a[x][y+1]=0;
a[x][y+2]=0;
ans++;
}
else if(h==-1 && v!=-1) {
a[x][y]=0;
a[x+1][y]=0;
a[x+2][y]=0;
ans++;
}
return 0;
}
if(p==1) {
if(d==1)
return c(x,y+1,1,2,(a[x-1][y]==1 && a[x+1][y]==3));
if(d==2)
return c(x+1,y,2,2,(a[x][y-1]==1 && a[x][y+1]==3));
}
if(p==2) {
if(d==1)
if(ol && a[x-1][y]==2 && a[max(0,x-2)][y]==1)
return -1;
else return ol;
if(d==2)
if(ol && a[x][y-1]==2 && a[x][max(0,y-2)]==1)
return -1;
else return ol;
}
}
int main() {
cin>>n>>m;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++) {
char t;
cin>>t;
if(t=='R')
a[i][j]=1;
else if(t=='G')
a[i][j]=2;
else a[i][j]=3;
}
//display();
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++) {
if(a[i][j]==1) {
c(i,j,0,0);
//display();
}
}
cout<<ans;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int c(int, int, int, int, int)':
dango_maker.cpp:58:11: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
58 | if(d==1)
| ^
dango_maker.cpp:62:11: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
62 | if(d==2)
| ^
dango_maker.cpp:67:1: warning: control reaches end of non-void function [-Wreturn-type]
67 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |