# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1178174 | ritikthakur2712 | Tracks in the Snow (BOI13_tracks) | C++20 | 1 ms | 584 KiB |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
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
int maxi = 1;
depth[0][0]=1;
while(!q.empty()){
int row = q.front().first;
int col = q.front().second;
// debug(row);debug(col);
maxi = max(maxi, depth[row][col]);
q.pop_front();
for(int i=0;i<4; i++){
int nrow = row + drow[i];
int ncol = col + dcol[i];
if( inside(nrow,ncol) && depth[nrow][ncol]==0 ){
if ( grid[nrow][ncol] == grid[row][col] ){
depth[nrow][ncol] = depth[row][col];
q.push_front({nrow,ncol});
}
else{
depth[nrow][ncol] = depth[row][col] + 1;
q.push_back({nrow,ncol});
}
}
}
}
cout<<maxi<<"\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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |