Submission #891814

#TimeUsernameProblemLanguageResultExecution timeMemory
891814seriouslyFlawedTracks in the Snow (BOI13_tracks)C++17
100 / 100
1100 ms119196 KiB
#include <bits/stdc++.h> using namespace std; // Shortcuts for common operations #define pb push_back #define ppb pop_back #define f first #define s second #define all(x) (x).begin(), (x).end() #define ll long long #define endl "\n" // Type definitions for convenience typedef vector<int> vi; typedef vector<bool> vb; typedef pair<int, int> pii; typedef vector<vi> vvi; typedef vector<pii> vii; typedef unordered_set<int> usi; typedef unordered_map<int, int> umii; // Debugging macros #define debug(x) cerr << #x << " = " << (x) << '\n' #define debug_vector(v) _debug_vector(#v, v) template<typename T> void _debug_vector(const string& name, const vector<T>& a) { cerr << name << " = [ "; for(const auto &x : a) cerr << x << ' '; cerr << "]\n"; } // I/O redirection for local testing #define iofile(io) \ freopen((io + ".in").c_str(), "r", stdin); \ freopen((io + ".out").c_str(), "w", stdout); // delta for floodfill vi dx = {0, 1, 0, -1}; vi dy = {1, 0, -1, 0}; // extended deltas for floodfill vi edx = {0, 1, 0, -1, 1, 1, -1, -1}; vi edy = {1, 0, -1, 0, 1, -1, 1, -1}; // Common outputs void yes() { cout << "YES" << '\n'; } void no() { cout << "NO" << '\n'; } // cin.tie(0)->sync_with_stdio(0); void fx() { // Functionality for fx int n, m; cin >> n >> m; vector<string>tab(n); for(auto &i: tab) cin >> i; vvi lvl(n, vi(m, 0)); lvl[0][0] = 1; queue<pii>q; q.push({0, 0}); queue<pii>que; int res = 1; while(!q.empty()){ while(!q.empty()){ auto curr = q.front(); q.pop(); for(int i = 0; i < 4; i++){ pii next = {curr.f+dx[i], curr.s+dy[i]}; if(next.f >= 0 and next.f <= n-1 and next.s >= 0 and next.s <= m-1){ if(tab[next.f][next.s] == '.' or lvl[next.f][next.s] != 0) continue; if(tab[next.f][next.s] == tab[curr.f][curr.s]){ q.push(next); lvl[next.f][next.s] = res; } else{ que.push(next); lvl[next.f][next.s] = res+1; } } } } if(q.empty()){ res++; swap(q, que); } } cout << (res-1) << endl; } int main() { // Uncomment the following lines for file I/O // iofile(string("hello")); // Uncomment the following lines for multiple test cases // int t; cin >> t; // while(t--) fx(); // Single test case fx(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...