Submission #1089436

#TimeUsernameProblemLanguageResultExecution timeMemory
1089436Alihan_8Tracks in the Snow (BOI13_tracks)C++17
100 / 100
599 ms199492 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; vector <string> s(h); for ( auto &u: s ){ cin >> u; for ( auto &v: u ){ v = (v == 'F' ? 0 : v == 'R' ? 1 : 2); } } vector <vector<bool>> us(h, vector <bool> (w)); auto ok = [&](int u, int v){ return u >= 0 && u < h && v >= 0 && v < w && !us[u][v]; }; int cnt = 0, t = s[0][0]; vector <pair<int,int>> q; q.pb({0, 0}); us[0][0] = 1; while ( !q.empty() ){ vector <pair<int,int>> nxt; for ( int i = 0; i < (int)q.size(); i++ ){ auto [u, v] = q[i]; for ( int j = 0; j < 4; j++ ){ int x = u + dx[j], y = v + dy[j]; if ( !ok(x, y) ) continue; us[x][y] = 1; if ( s[x][y] == t ){ q.pb({x, y}); } else if ( s[x][y] != 2 ) nxt.pb({x, y}); } } cnt += 1; t ^= 1; swap(nxt, q); } cout << cnt; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...