# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1020049 | 7again | Tracks in the Snow (BOI13_tracks) | C++17 | 2096 ms | 1048576 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 int long long
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define FAST ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)
using namespace std ;
void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
const int N = 2e5 , MOD = 1e9+7 ;
int xis[4]{1 , -1 , 0 , 0} , yis[4]{0 , 0 , 1 , -1} ;
int n , m ;
vector <int> v[N] ;
bool inside(int x , int y)
{
return (x < n && x > -1 && y < m && y > -1) ;
}
void slv()
{
cin >> n >> m ;
char a[n][m] ;
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < m ; j++)
cin >> a[i][j] ;
int depth[n][m]{0} ;
deque <pair <int , int>> q ;
q.push_back({0 , 0}) ;
depth[0][0] = 0 ;
int mx = 1 ;
while(!q.empty())
{
pair <int , int> t = q.front() ;
q.pop_back() ;
mx = max(mx , depth[t.f][t.s]) ;
for(int i = 0 ; i < 4 ; i++)
{
int x = t.f + xis[i] , y = t.s = yis[i] ;
if(inside(x , y) && depth[x][y] == 0)
{
if(a[x][y] == a[t.f][t.s])
{
depth[x][y] = depth[t.f][t.s] ;
q.push_back({x , y}) ;
}
else
{
depth[x][y] = depth[t.f][t.s] + 1 ;
q.push_front({x , y}) ;
}
}
}
}
cout << mx ;
}
main()
{
//FAST ;
slv() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |