# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133988 | CaroLinda | Tracks in the Snow (BOI13_tracks) | C++14 | 1750 ms | 260688 KiB |
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 4010
#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 valid(int x, int y)
{ return (x>=0 && x< n && y>=0 && y<m) ; }
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);
}
vector<pii> firstGroup , secondGroup ;
firstGroup.pb( pii(0,0) ) ;
int ini = 0 ;
lp(i,0,n)
lp(j,0,m)
id[i][j] = MAXN+10 ;
id[0][0] = 1 ;
int s = 0 ;
while( firstGroup.size() != 0 )
{
secondGroup.resize(0) ;
s++ ;
while( ini < firstGroup.size() )
{
pii p = firstGroup[ini++] ;
for(int i = 0 ; i < 4 ; i++)
{
int x = p.ff + dx[i] ;
int y = p.ss + dy[i] ;
if( !valid(x,y) || id[x][y] <= id[p.ff][p.ss] ) continue ;
if( mat[x][y] == mat[p.ff][p.ss] )
{
id[x][y] = id[p.ff][p.ss] ;
firstGroup.pb( pii(x,y) ) ;
}
else if ( mat[x][y] == !mat[p.ff][p.ss] )
{
id[x][y] = id[p.ff][p.ss] + 1 ;
secondGroup.pb( pii(x,y) ) ;
}
}
}
firstGroup.resize(0) ;
lp(i,0,secondGroup.size() )
firstGroup.pb( secondGroup[i] ) ;
}
printf("%d\n" , s ) ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |