Submission #757691

#TimeUsernameProblemLanguageResultExecution timeMemory
757691drdilyorTracks in the Snow (BOI13_tracks)C++17
82.50 / 100
2108 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; auto dfs = [&](auto& dfs, int i, int d) -> void { vis[i] = 1; dist[i] = d; for (auto [e, ec]: adj[i]) { if (vis[e]) continue; if (ec) {if (!vis[e]) edge.push_back(e);} else dfs(dfs, e, d); } res = max(res, dist[i]); }; dfs(dfs, 0, 1); for (int d = 2; edge.size(); d ++) { auto cur = std::move(edge); for (int k : cur) dfs(dfs, k, d); } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...