Submission #888471

#TimeUsernameProblemLanguageResultExecution timeMemory
888471bashNewbieTracks in the Snow (BOI13_tracks)C++17
75.83 / 100
1031 ms140720 KiB
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> using namespace std; #define fast_io ios::sync_with_stdio(0), cin.tie(0) #define vi vector<int> #define vvi vector<vi> #define vs vector<string> #define pb push_back int main() { fast_io; int n, m; cin >> n >> m; vs s(n); for(auto &t: s) cin >> t; auto in = [&] (int x) { return -1 < x && x < n*m; }; auto bad = [&] (int x) { return s[x/m][x%m] == '.'; }; auto same = [&] (int x, int y) { int xr = x/m, xc = x%m, yr = y/m, yc = y%m; return s[xr][xc] == s[yr][yc]; }; queue<int> q, nq; vi vis(n*m), adj = {-m, -1, 1, m}; int ret = 0; q.push(0), vis[0] = 1; while(!q.empty()) { ret++; while(!q.empty()) { int x = q.front(); q.pop(), nq.push(x); for(int c: adj) { int y = x+c; if(!in(y) || vis[y] || bad(y) || !same(x, y)) continue; q.push(y), vis[y] = 1; } } while(!nq.empty()) { int x = nq.front(); nq.pop(); for(int c: adj) { int y = x+c; if(!in(y) || vis[y] || bad(y)) continue; q.push(y), vis[y] = 1; } } } cout << ret << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...