Submission #334280

# Submission time Handle Problem Language Result Execution time Memory
334280 2020-12-08T22:57:34 Z CaroLinda Zoo (COCI19_zoo) C++14
110 / 110
121 ms 7316 KB
#include <bits/stdc++.h>

const int MAX = 1010 ;

using namespace std ;

int n , m ;
int dx[4] = {1,-1,0,0} ;
int dy[4] = {0,0,1,-1} ;
int dist[MAX][MAX] ;
char grid[MAX][MAX] ;
bool vis[MAX][MAX] ;

bool valid(int i, int j) { return 1 <= i && 1 <= j && i <= n && j <= m ; }

int main()
{
	scanf("%d %d", &n , &m ) ;
	for(int i = 1 ; i <= n ; i++ )
		for(int j = 1 ; j <= m ; j++ ) scanf(" %c", &grid[i][j] ) , dist[i][j] = n+m+1 ;

	deque< pair<int,int> > fila ;
	fila.push_back( make_pair(1,1) ) ;
	dist[1][1] = 1 ;

	int ans = 1 ;

 	while(!fila.empty() )
 	{
 		int i = fila[0].first ;
 		int j = fila[0].second ;
 		fila.pop_front() ;

 		if( vis[i][j] ) continue ;
		
		ans = max(ans, dist[i][j] ) ;
 		vis[i][j] = true ;

 		for(int g = 0 , ni , nj ;  g < 4 ; g++ )
 		{
 			ni = i + dx[g] ;
 			nj = j + dy[g] ;

			if(!valid(ni,nj) || grid[ni][nj] == '*' ) continue ;

			if( grid[ni][nj] == grid[i][j] )
			{
				if( dist[ni][nj] <= dist[i][j] ) continue ;
				dist[ni][nj] = dist[i][j] ;
				fila.push_front( make_pair(ni,nj) ) ;
			}
			else 
			{
				if( dist[ni][nj] <= dist[i][j] + 1 ) continue ;
				dist[ni][nj] = dist[i][j] + 1 ;
				fila.push_back( make_pair(ni,nj) ) ;	
			}

 		}

 	}
	
	printf("%d\n", ans ) ;
}

Compilation message

zoo.cpp: In function 'int main()':
zoo.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  scanf("%d %d", &n , &m ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
zoo.cpp:20:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   for(int j = 1 ; j <= m ; j++ ) scanf(" %c", &grid[i][j] ) , dist[i][j] = n+m+1 ;
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 0 ms 1004 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 2 ms 876 KB Output is correct
12 Correct 2 ms 876 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 0 ms 1004 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 1004 KB Output is correct
11 Correct 2 ms 876 KB Output is correct
12 Correct 2 ms 876 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 64 ms 7204 KB Output is correct
17 Correct 63 ms 7148 KB Output is correct
18 Correct 67 ms 7276 KB Output is correct
19 Correct 80 ms 7148 KB Output is correct
20 Correct 64 ms 7148 KB Output is correct
21 Correct 121 ms 6892 KB Output is correct
22 Correct 101 ms 6892 KB Output is correct
23 Correct 111 ms 7148 KB Output is correct
24 Correct 109 ms 7276 KB Output is correct
25 Correct 114 ms 7316 KB Output is correct
26 Correct 121 ms 6892 KB Output is correct
27 Correct 105 ms 7020 KB Output is correct
28 Correct 107 ms 7020 KB Output is correct
29 Correct 109 ms 7276 KB Output is correct
30 Correct 120 ms 7148 KB Output is correct