This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) ; }
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] ) v.pb(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 , ini = 0 ;
v.pb(pii(0,0) ) ;
int ant = -1 ;
while( ini < v.size() )
{
pii p = v[ini++] ;
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 (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:56:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( ini < v.size() )
~~~~^~~~~~~~~~
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |