Submission #134000

#TimeUsernameProblemLanguageResultExecution timeMemory
134000CaroLindaTracks in the Snow (BOI13_tracks)C++14
29.58 / 100
1869 ms646392 KiB
#include <bits/stdc++.h>

#define MAXN 4005
#define lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back

using namespace std ;

int n , m ;
int mat[MAXN][MAXN] , id[MAXN][MAXN] ;
int dx[4] = {1,0,-1,0} ;
int dy[4] = {0,-1,0,1} ;
bool marc[MAXN][MAXN] ;


bool valid(int x, int y)
{ return (x>=0 && x< n && y>=0 && y<m) ; }

pii prox = pii(0,0) ;

void dfs(int x, int y)
{
	marc[x][y] = true ;
	lp(i,0,4)
	{
		int a = x + dx[i] ;
		int b= y+dy[i] ;
		if( !valid(a,b) || marc[a][b] ) continue ;
		if( mat[a][b] == mat[x][y] ) dfs(a,b) ;
		else if( mat[a][b] == !mat[x][y] ) prox = pii(a,b) ;
	}
}

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);
		}

	memset(marc,false,sizeof marc) ;
	
	int  s = 0 ;

	while( prox != pii(-1,-1) )
	{
		s++ ;
		pii p = prox ;
		
		prox = pii(-1,-1) ;
		dfs(p.ff, p.ss) ;
	}
	printf("%d\n", s ) ;
}

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:39: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:44:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &c ) ;
    ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...