제출 #333971

#제출 시각아이디문제언어결과실행 시간메모리
333971codemaster111Tracks in the Snow (BOI13_tracks)C++14
100 / 100
954 ms130812 KiB
#include <bits/stdc++.h> using namespace std; const int MX = 4001; int n, m, d[MX][MX], dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; string g[MX]; bool inside(int r, int c) { return (r >= 0 && r < n && c >= 0 && c < m && g[r][c] != '.'); } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> g[i]; int ans = 1; d[0][0] = 1; deque<pair<int, int>> q; q.push_front({0, 0}); while (!q.empty()) { pair<int, int> v = q.front(); q.pop_front(); ans = max(ans, d[v.first][v.second]); for (int i = 0; i < 4; ++i) { int x = v.first+dx[i], y = v.second+dy[i]; if (inside(x, y) && d[x][y] == 0) { if (g[x][y] == g[v.first][v.second]) { d[x][y] = d[v.first][v.second]; q.push_front({x, y}); } else { d[x][y] = d[v.first][v.second]+1; q.push_back({x, y}); } } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...