제출 #1245405

#제출 시각아이디문제언어결과실행 시간메모리
1245405mohamedyehiaTracks in the Snow (BOI13_tracks)C++20
0 / 100
849 ms229160 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ffr(i, s, n) for (int i = s; i < n; i++) vector<vll> depth; ll ans = 1; vll dx = {-1, 1, 0, 0}; vll dy = {0, 0, -1, 1}; bool check_in_side(ll i, ll j, ll n, ll m) { return (i >= 0 && i < n && j >= 0 && j < m); } void bfs(ll n, ll m, vector<string> &snow) { // build the queue deque<pll> q; // strarting from node 0 , 0; q.push_front(make_pair(0, 0)); // its depth is 1; but i have a question what about if there is no animal ? // how we deal with '.' depth[0][0] = 1; while (!q.empty()) { // pop the forntier; pll forntier = q.front(); q.pop_front(); // make the code easier by taking the x, and y ll x = forntier.first; ll y = forntier.second; // update ans if needed ans = max(ans, depth[x][y]); // go through each child for (int i = 0; i < 4; i++) { ll nx = x + dx[i]; ll ny = y + dy[i]; // if they are not visited and inside the boundaries queue them if (check_in_side(nx, ny, n, m) && depth[nx][ny] == 0) { // give high proirity for the similar nodes if (snow[nx][ny] == snow[x][y]) { q.push_front(make_pair(nx, ny)); depth[nx][ny] = depth[x][y]; } else // lowest priority { q.push_back(make_pair(nx, ny)); depth[nx][ny] = depth[x][y] + 1; } } } } } void solve() { ll n, m; cin >> n >> m; depth.assign(n, vector<ll>(m)); vector<string> snow(n); ffr(i, 0, n) { cin >> snow[i]; } bfs(n, m , snow); cout << ans - 1 << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // freopen("milkvisits.out", "r", stdin); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...