#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
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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |