Submission #757667

#TimeUsernameProblemLanguageResultExecution timeMemory
757667drdilyorTracks in the Snow (BOI13_tracks)C++17
80.31 / 100
2108 ms1048576 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimize("unroll-loops") #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}); } } } } vector<int> dist(n*m, -1); priority_queue<pair<int,int>> p; p.push({0, 0}); while (p.size()) { auto [w, v] = p.top(); p.pop(); if (dist[v] != -1) continue; dist[v] = -w; for (auto [e, ew]: adj[v]) { if (dist[e] == -1) { p.push({w - ew, e}); } } } cout << *max_element(dist.begin(), dist.end()) +1 << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...