Submission #790783

#TimeUsernameProblemLanguageResultExecution timeMemory
790783KindaNamelessTracks in the Snow (BOI13_tracks)C++14
100 / 100
576 ms130912 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; char M[4001][4001]; int dist[4001][4001]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int H, W; cin >> H >> W; for(int i = 1; i <= H; ++i){ for(int j = 1; j <= W; ++j){ cin >> M[i][j]; dist[i][j] = 1e9; } } deque<pair<int, int>> dq; dq.push_front({1, 1}); dist[1][1] = 1; int answer = 1; while(!dq.empty()){ int x, y; tie(x, y) = dq.front(); dq.pop_front(); for(int k = 0; k < 4; ++k){ int nx = x + dx[k], ny = y + dy[k]; if(nx > 0 && ny > 0 && nx <= H && ny <= W && dist[nx][ny] == 1e9 && M[nx][ny] != '.'){ dist[nx][ny] = dist[x][y]; if(M[x][y] != M[nx][ny]){ dist[nx][ny]++; dq.push_back({nx, ny}); } else{ dq.push_front({nx, ny}); } answer = max(answer, dist[nx][ny]); } } } cout << answer; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...