Submission #715018

#TimeUsernameProblemLanguageResultExecution timeMemory
715018mariacichoszTracks in the Snow (BOI13_tracks)C++17
100 / 100
698 ms140892 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define sz size #define st first #define nd second const int N = 4010; const int inf = 1e9 + 3; int h, w; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int dis[N][N]; bool vis[N][N]; char tab[N][N]; int ans; void bfs(int x = 1, int y = 1){ deque<pii> q; vis[x][y] = 1; dis[x][y] = 1; q.push_front({x, y}); while (!q.empty()){ auto v = q.front(); q.pop_front(); int sx = v.st, sy = v.nd; ans = max(dis[sx][sy], ans); for (int i = 0; i < 4; i ++){ int nx = sx + dx[i], ny = sy + dy[i]; if (nx < 1 || ny < 1 || nx > h || ny > w) continue; if (vis[nx][ny]) continue; if (tab[nx][ny] == '.') continue; if (tab[nx][ny] == tab[sx][sy]){ dis[nx][ny] = dis[sx][sy]; vis[nx][ny] = 1; q.push_front({nx, ny}); } if (tab[nx][ny] != tab[sx][sy]){ dis[nx][ny] = dis[sx][sy] + 1; vis[nx][ny] = 1; q.push_back({nx, ny}); } } } } void cl(){ for (int i = 0; i < N; i ++){ for (int j = 0; j < N; j ++){ dis[i][j] = inf; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cl(); cin >> h >> w; for (int i = 1; i <= h; i ++){ for (int j = 1; j <= w; j ++){ cin >> tab[i][j]; } } bfs(); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...