Submission #366953

#TimeUsernameProblemLanguageResultExecution timeMemory
366953vishesh312Tracks in the Snow (BOI13_tracks)C++17
100 / 100
1148 ms984844 KiB
#include "bits/stdc++.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; vector<string> v; int n, m; int ans = 0; array<vector<array<int, 2>>, 2> cur; bool isValid(int i, int j) { return i < n and i >= 0 and j < m and j >= 0 and v[i][j] != '.'; } vector<array<int, 2>> moves = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; void dfs(array<int, 2> a) { char c = v[a[0]][a[1]]; v[a[0]][a[1]] = '.'; for (auto m : moves) { int nx = a[0] + m[0], ny = a[1] + m[1]; if (isValid(nx, ny)) { if (v[nx][ny] == c) { dfs({nx, ny}); } else { cur[ans&1?0:1].push_back({nx, ny}); } } } } void solve(int tc) { cin >> n >> m; v.resize(n); for (auto &x : v) cin >> x; cur[0].push_back({0, 0}); while (!cur[ans&1].empty()) { for (auto x : cur[ans&1]) { if (isValid(x[0], x[1])) { dfs(x); } } cur[ans&1].clear(); ++ans; } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...