# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1178182 | ritikthakur2712 | Tracks in the Snow (BOI13_tracks) | C++20 | 2 ms | 584 KiB |
#include<bits/stdc++.h>
using namespace std;
int drow[4]{1, -1, 0, 0}, dcol[4]{0, 0, 1, -1};
int n, m, depth[4000][4000], ans = 1;
string grid[4000];
bool inside(int x, int y) {
return (x > -1 && x < n && y > -1 && y < m && grid[x][y] != '.');
}
void solve(){
cin>>n>>m;
for(int i=0; i<n; i++){
cin>>grid[i];
}
// todo: find the layers in the grid, like how deep can we go into the grid
deque<pair<int,int>>q;
q.push_back({0,0}); // top-left corner
depth[0][0]=1;
while(q.size()){
pair<int,int>c = q.front();
q.pop_front();
ans = max(ans, depth[c.first][c.second]);
for(int i=0;i<4; i++){
int x = c.first + drow[i];
int y = c.second + dcol[i];
if( inside(x,y) && depth[x][y]==0 ){
if ( grid[x][y] == grid[c.first][c.second] ){
depth[x][y] = depth[c.first][c.second];
q.push_front({x,y});
}
else{
depth[x][y] = depth[c.first][c.second] + 1;
q.push_back({x,y});
}
}
}
}
cout<<ans<<"\n";
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |