Submission #134019

# Submission time Handle Problem Language Result Execution time Memory
134019 2019-07-21T23:26:21 Z CaroLinda Tracks in the Snow (BOI13_tracks) C++14
93.4375 / 100
2000 ms 836344 KB
    #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 ) ;
    }

Compilation message

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 time Memory Grader output
1 Correct 37 ms 8304 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 24 ms 8516 KB Output is correct
5 Correct 12 ms 4392 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 1148 KB Output is correct
9 Correct 4 ms 1528 KB Output is correct
10 Correct 11 ms 3832 KB Output is correct
11 Correct 8 ms 3576 KB Output is correct
12 Correct 17 ms 4848 KB Output is correct
13 Correct 12 ms 4344 KB Output is correct
14 Correct 12 ms 4344 KB Output is correct
15 Correct 34 ms 8432 KB Output is correct
16 Correct 37 ms 8304 KB Output is correct
17 Correct 30 ms 7668 KB Output is correct
18 Correct 24 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 40820 KB Output is correct
2 Correct 150 ms 25080 KB Output is correct
3 Correct 1112 ms 110020 KB Output is correct
4 Correct 296 ms 41832 KB Output is correct
5 Correct 756 ms 136340 KB Output is correct
6 Correct 1836 ms 177660 KB Output is correct
7 Correct 55 ms 42616 KB Output is correct
8 Correct 49 ms 40952 KB Output is correct
9 Correct 7 ms 1272 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 44 ms 39936 KB Output is correct
12 Correct 6 ms 2424 KB Output is correct
13 Correct 150 ms 25188 KB Output is correct
14 Correct 89 ms 16344 KB Output is correct
15 Correct 95 ms 18332 KB Output is correct
16 Correct 64 ms 9832 KB Output is correct
17 Correct 370 ms 47036 KB Output is correct
18 Correct 357 ms 48396 KB Output is correct
19 Correct 298 ms 41972 KB Output is correct
20 Correct 261 ms 38440 KB Output is correct
21 Correct 679 ms 89152 KB Output is correct
22 Correct 769 ms 136380 KB Output is correct
23 Correct 709 ms 74196 KB Output is correct
24 Correct 663 ms 84360 KB Output is correct
25 Correct 1468 ms 127944 KB Output is correct
26 Execution timed out 2084 ms 836344 KB Time limit exceeded
27 Execution timed out 2001 ms 504028 KB Time limit exceeded
28 Correct 1780 ms 177664 KB Output is correct
29 Correct 1728 ms 172272 KB Output is correct
30 Correct 1844 ms 271316 KB Output is correct
31 Correct 1342 ms 142076 KB Output is correct
32 Execution timed out 2089 ms 449272 KB Time limit exceeded