제출 #134019

#제출 시각아이디문제언어결과실행 시간메모리
134019CaroLindaTracks in the Snow (BOI13_tracks)C++14
93.44 / 100
2089 ms836344 KiB
    #include <bits/stdc++.h>
     
    #define MAXN 4002
    #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] ;
    int dx[4] = {1,0,-1,0} ;
    int dy[4] = {0,-1,0,1} ;
    bool marc[MAXN][MAXN] , marc2[MAXN][MAXN] ;
     
     
    bool valid(int x, int y)
    { return (x>=0 && x< n && y>=0 && y<m) ; }
     
    vector<pii> v ;
     
    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] && !marc2[a][b] ) v.pb(pii(a,b) ) , marc2[a][b]=true ;
    	}
    }
     
    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  s = 0 , ini = 0 ;
    	v.pb(pii(0,0) ) ;
     
    	int ant = -1 ;
     
    	while( ini < v.size() )
    	{
    		pii p = v[ini++] ;
    		if(marc[p.ff][p.ss]) continue ;
    		if( mat[p.ff][p.ss] != ant ) { ant = mat[p.ff][p.ss] ; s++ ;}
    		dfs(p.ff, p.ss) ;
    	}
    	printf("%d\n", s ) ;
    }

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:54:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      while( ini < v.size() )
             ~~~~^~~~~~~~~~
tracks.cpp:39:11: 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:13: 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...