#include <bits/stdc++.h>
#define MAXN 4010
#define lp(i,a,b) for(int i=a;i<b;i++)
using namespace std ;
int n , m ;
int mat[MAXN][MAXN] ;
int dx[4] = {1,0,-1,0} ;
int dy[4] = {0,-1,0,1} ;
bool valid(int x, int y)
{ return (x>=0 && x< n && y>=0 && y<m) ; }
int tot = 0 ;
int dfs(int x , int y , int busco)
{
tot ++ ;
mat[x][y] = !busco ;
lp(i,0,4)
{
int a = x + dx[i] ;
int b = y+dy[i] ;
if( !valid(a,b) || mat[a][b] != busco ) continue ;
dfs(a,b,busco) ;
}
}
int main()
{
scanf("%d%d", &n , &m ) ;
lp(i,0,n)
lp(j,0,m)
{
char c ;
scanf(" %c", &c ) ;
if(c=='.') mat[i][j] = -1 ;
else mat[i][j] = (c=='R'?0:1);
}
int ant = 0 , animal = 0 ;
while(true)
{
tot = 0 ;
dfs(0,0,mat[0][0]) ;
if( ant == tot ) break ;
animal ++ ;
ant = tot ;
}
printf("%d\n" , animal ) ;
}
Compilation message
tracks.cpp: In function 'int dfs(int, int, int)':
tracks.cpp:34:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
tracks.cpp: In function 'int main()':
tracks.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n , &m ) ;
~~~~~^~~~~~~~~~~~~~~~~~
tracks.cpp:43:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &c ) ;
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
13688 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
37 ms |
10104 KB |
Output is correct |
5 |
Correct |
50 ms |
2424 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
760 KB |
Output is correct |
10 |
Correct |
50 ms |
1784 KB |
Output is correct |
11 |
Correct |
10 ms |
3192 KB |
Output is correct |
12 |
Correct |
59 ms |
5240 KB |
Output is correct |
13 |
Correct |
50 ms |
2296 KB |
Output is correct |
14 |
Correct |
50 ms |
2372 KB |
Output is correct |
15 |
Correct |
321 ms |
5112 KB |
Output is correct |
16 |
Correct |
214 ms |
13560 KB |
Output is correct |
17 |
Correct |
357 ms |
6472 KB |
Output is correct |
18 |
Correct |
37 ms |
10080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1445 ms |
16680 KB |
Output is correct |
2 |
Execution timed out |
2051 ms |
15688 KB |
Time limit exceeded |
3 |
Execution timed out |
2058 ms |
63816 KB |
Time limit exceeded |
4 |
Execution timed out |
2054 ms |
34176 KB |
Time limit exceeded |
5 |
Execution timed out |
2056 ms |
48816 KB |
Time limit exceeded |
6 |
Execution timed out |
2103 ms |
555056 KB |
Time limit exceeded |
7 |
Correct |
1229 ms |
17144 KB |
Output is correct |
8 |
Correct |
1424 ms |
16788 KB |
Output is correct |
9 |
Correct |
103 ms |
1400 KB |
Output is correct |
10 |
Correct |
241 ms |
800 KB |
Output is correct |
11 |
Correct |
428 ms |
16632 KB |
Output is correct |
12 |
Correct |
1211 ms |
1620 KB |
Output is correct |
13 |
Execution timed out |
2047 ms |
15496 KB |
Time limit exceeded |
14 |
Execution timed out |
2037 ms |
10156 KB |
Time limit exceeded |
15 |
Execution timed out |
2068 ms |
9480 KB |
Time limit exceeded |
16 |
Execution timed out |
2070 ms |
6728 KB |
Time limit exceeded |
17 |
Execution timed out |
2069 ms |
29600 KB |
Time limit exceeded |
18 |
Execution timed out |
2077 ms |
26548 KB |
Time limit exceeded |
19 |
Execution timed out |
2085 ms |
34168 KB |
Time limit exceeded |
20 |
Execution timed out |
2085 ms |
23516 KB |
Time limit exceeded |
21 |
Execution timed out |
2063 ms |
50152 KB |
Time limit exceeded |
22 |
Execution timed out |
2074 ms |
48760 KB |
Time limit exceeded |
23 |
Execution timed out |
2067 ms |
44004 KB |
Time limit exceeded |
24 |
Execution timed out |
2070 ms |
49636 KB |
Time limit exceeded |
25 |
Execution timed out |
2068 ms |
63656 KB |
Time limit exceeded |
26 |
Execution timed out |
2107 ms |
638320 KB |
Time limit exceeded |
27 |
Execution timed out |
2105 ms |
629088 KB |
Time limit exceeded |
28 |
Execution timed out |
2104 ms |
505388 KB |
Time limit exceeded |
29 |
Execution timed out |
2089 ms |
558716 KB |
Time limit exceeded |
30 |
Execution timed out |
2093 ms |
445944 KB |
Time limit exceeded |
31 |
Execution timed out |
2069 ms |
162896 KB |
Time limit exceeded |
32 |
Execution timed out |
2088 ms |
574968 KB |
Time limit exceeded |