Submission #1322351

#TimeUsernameProblemLanguageResultExecution timeMemory
1322351stathiskonsTracks in the Snow (BOI13_tracks)C++20
100 / 100
399 ms28332 KiB
// #include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; void solve(void){ int n, m; cin >> n >> m; vector<string> g(n); for(auto& s : g) cin >> s; queue<pi> q, q2; q.emplace(0, 0); int ans = 0; char cur = g[0][0]; char other = cur == 'F' ? 'R' : 'F'; auto out = [&](int i, int j) -> bool { return i < 0 || j < 0 || i >= n || j >= m; }; const int di[] = {-1, 1, 0, 0}; const int dj[] = {0, 0, -1, 1}; while(!q.empty()) { ans++; while(!q.empty()) { auto [i, j] = q.front(); q.pop(); for(int k = 0 ; k < 4 ; k++) { int ni = i + di[k]; int nj = j + dj[k]; if(!out(ni, nj)) { if(g[ni][nj] == cur) { q.emplace(ni, nj); } else if(g[ni][nj] == other) { q2.emplace(ni, nj); } g[ni][nj] = '$'; } } } swap(q, q2); swap(cur, other); } cout << ans << "\n"; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...