Submission #757696

#TimeUsernameProblemLanguageResultExecution timeMemory
757696drdilyorTracks in the Snow (BOI13_tracks)C++17
82.50 / 100
2084 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; vector<string> mat(n); for (string& s : mat) { cin >> s; } auto id = [m](int i, int j) { return i* m + j;}; vector<vector<pair<int,int>>> adj(n * m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (auto [di, dj] : {pair{0, -1}, {0, 1}, {-1, 0}, {1, 0}}) { int ni = i + di; int nj = j + dj; if (clamp(ni, 0,n-1) == ni && clamp(nj, 0, m-1) == nj) { if (mat[ni][nj] == '.' || mat[i][j] == '.') continue; int c = mat[i][j] != mat[ni][nj]; adj[id(i, j)].push_back({id(ni, nj), c}); } } } } static constexpr int inf = 1e9; vector<int> dist(n*m, inf), vis(n*m, 0); int res = 0; vector<int> edge; vector<int> stk; auto dfs = [&](int i, int d) -> void { stk.clear(); stk.push_back(i); while (stk.size()) { int i = stk.back(); stk.pop_back(); vis[i] = 1; dist[i] = d; for (auto [e, ec]: adj[i]) { if (vis[e]) continue; if (ec) {vis[e] = 1, edge.push_back(e);} else stk.push_back(e); } res = max(res, dist[i]); } }; dfs(0, 1); for (int d = 2; edge.size(); d ++) { int k = edge.size(); auto cur = std::move(edge); for (int k : cur) dfs(k, d); } cout << res << '\n'; return 0; }

Compilation message (stderr)

tracks.cpp: In function 'int main()':
tracks.cpp:55:13: warning: unused variable 'k' [-Wunused-variable]
   55 |         int k = edge.size();
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...