제출 #716277

#제출 시각아이디문제언어결과실행 시간메모리
716277nima_aryanTracks in the Snow (BOI13_tracks)C++17
0 / 100
2148 ms891740 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #endif using i64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int H, W; cin >> H >> W; vector grid(H, vector<char>(W)); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { cin >> grid[i][j]; } } auto id = [&](int i, int j) { return W * i + j; }; auto di = [&](int i) { return make_pair(i / W, i % W); }; const int N = H * W; vector<vector<int>> graph(N); auto add_edge = [&](int a, int b) { graph[a].push_back(b); graph[b].push_back(a); }; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (j + 1 < W) { add_edge(id(i, j), id(i, j + 1)); } if (i + 1 < H) { add_edge(id(i, j), id(i + 1, j)); } } } auto get = [&](int node) { auto [i, j] = di(node); return grid[i][j]; }; const int inf = (int) 1e9; vector<int> dist(N, inf); deque<int> dq; auto add = [&](int u, int d, int ex = 0) { if (ex) { dq.push_back(u); } else { dq.push_front(u); } dist[u] = d + ex; }; add(0, 0); int ans = 0; while (!dq.empty()) { int node = dq.front(); dq.pop_front(); ans = max(ans, dist[node]); for (int neighbor : graph[node]) { if (dist[neighbor] < inf) { continue; } add(neighbor, dist[node], get(node) != get(neighbor)); } } cout << ans << '\n'; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...