Submission #1284769

#TimeUsernameProblemLanguageResultExecution timeMemory
1284769blackscreen1Tracks in the Snow (BOI13_tracks)C++20
61.04 / 100
725 ms320976 KiB
#include <bits//stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; #define ll long long #define ld long double #define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1)) #define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1)) #define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1)) #define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1)) #define iloop_(m, h, g) for (auto i = m; i < h; i += g) #define jloop_(m, h, g) for (auto j = m; j < h; j += g) #define kloop_(m, h, g) for (auto k = m; k < h; k += g) #define lloop_(m, h, g) for (auto l = m; l < h; l += g) #define getchar_unlocked _getchar_nolock // comment before submission #define pll pair<ll, ll> #define plll pair<ll, pll> #define pllll pair<pll, pll> #define vll vector<ll> #define qll queue<ll> #define dll deque<ll> #define pqll priority_queue<ll> #define gll greater<ll> #define INF 1000000000000000 #define MOD1 1000000007 #define MOD2 998244353 #define MOD3 1000000009 mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; char a[n][m]; iloop(0, n) jloop(0, m) cin >> a[i][j]; ll ds[n][m]; iloop(0, n) jloop(0, m) ds[i][j] = INF; bool vis[n][m]; memset(vis, 0, sizeof(vis)); ds[0][0] = 0; deque<pll> dq; dq.push_back({0, 0}); while (dq.size()) { pll nd = dq.front(); dq.pop_front(); if (a[nd.first][nd.second] == '.') continue; if (vis[nd.first][nd.second]) continue; vis[nd.first][nd.second] = 1; if (nd.first != 0 && !vis[nd.first-1][nd.second]) { if (a[nd.first][nd.second] == a[nd.first-1][nd.second]) { ds[nd.first-1][nd.second] = ds[nd.first][nd.second]; dq.push_front({nd.first-1, nd.second}); } else if (ds[nd.first-1][nd.second] == INF) { ds[nd.first-1][nd.second] = ds[nd.first][nd.second] + 1; dq.push_back({nd.first-1, nd.second}); } } if (nd.first != n-1 && !vis[nd.first+1][nd.second]) { if (a[nd.first][nd.second] == a[nd.first+1][nd.second]) { ds[nd.first+1][nd.second] = ds[nd.first][nd.second]; dq.push_front({nd.first+1, nd.second}); } else if (ds[nd.first+1][nd.second] == INF) { ds[nd.first+1][nd.second] = ds[nd.first][nd.second] + 1; dq.push_back({nd.first+1, nd.second}); } } if (nd.second != 0 && !vis[nd.first][nd.second-1]) { if (a[nd.first][nd.second] == a[nd.first][nd.second-1]) { ds[nd.first][nd.second-1] = ds[nd.first][nd.second]; dq.push_front({nd.first, nd.second-1}); } else if (ds[nd.first][nd.second-1] == INF) { ds[nd.first][nd.second-1] = ds[nd.first][nd.second] + 1; dq.push_back({nd.first, nd.second-1}); } } if (nd.second != m-1 && !vis[nd.first][nd.second+1]) { if (a[nd.first][nd.second] == a[nd.first][nd.second+1]) { ds[nd.first][nd.second+1] = ds[nd.first][nd.second]; dq.push_front({nd.first, nd.second+1}); } else if (ds[nd.first][nd.second+1] == INF) { ds[nd.first][nd.second+1] = ds[nd.first][nd.second] + 1; dq.push_back({nd.first, nd.second+1}); } } } ll cans = 0; iloop(0, n) jloop(0, n) if (a[i][j] != '.') cans = max(cans, ds[i][j]); cout << cans + 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...