이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
/*
* BFS 0/1
* Dla krawedzi o wagach 0 lub 1.
* Zadanie: BOI 2013 Tracks in the Snow: https://oj.uz/problem/view/BOI13_tracks
*/
#define LL long long
#define ULL unsigned LL
#define LD long double
const int N = 4e3 + 4;
int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int n, m, depth[N][N];
string snow[N];
bool inside(int x, int y) {
return (x > -1 && x < n && y > -1 && y < m && snow[x][y] != '.');
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0; i<n; i++)
cin>>snow[i];
deque<pair<int, int>> q;
q.push_back({0, 0});
depth[0][0] = 1;
int ans = 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+dx[i], y = c.second+dy[i];
if(inside(x, y) && depth[x][y] == 0) {
if(snow[x][y] == snow[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;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |