Submission #369241

#TimeUsernameProblemLanguageResultExecution timeMemory
369241vm152Tracks in the Snow (BOI13_tracks)C++17
100 / 100
633 ms123900 KiB
#include <bits/stdc++.h> using namespace std ; #define ios ios_base::sync_with_stdio(0); cin.tie(0) ; cout.tie(0) #define eb emplace_back #define mp make_pair #define f first #define s second #define endl '\n' typedef long long int ll ; typedef long double lb ; typedef unsigned long long int ul ; const ll MOD = 1e9 + 7 ; int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1} ; void solve(){ int h, w ; cin >> h >> w ; string s[h] ; for (int i = 0; i < h; i++) cin >> s[i] ; deque<pair<int, int>> q ; int dist[h][w] ; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) dist[i][j] = 0 ; int ans = 0 ; q.push_back({0, 0}) ; dist[0][0] = 1 ; while (!q.empty()) { pair<int, int> c = q.front() ; q.pop_front() ; ans = max(ans, dist[c.f][c.s]) ; for (int i = 0; i < 4; i++) { int x = c.f + dx[i]; int y = c.s + dy[i] ; if (x < 0 || x >= h || y < 0 || y >= w || s[x][y] == '.') continue ; if (dist[x][y] == 0) { if (s[x][y] == s[c.f][c.s]) { dist[x][y] = dist[c.f][c.s] ; q.push_front({x, y}) ; } else { dist[x][y] = dist[c.f][c.s] + 1 ; q.push_back({x, y}) ; } } } } cout << ans << endl ; } int main(){ ios ; solve() ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...