제출 #1315641

#제출 시각아이디문제언어결과실행 시간메모리
1315641ivycubeTracks in the Snow (BOI13_tracks)C++20
100 / 100
380 ms118904 KiB
#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <queue> using namespace std; const int N = 4000; int n, m, region[N][N], ans = 1; string snow[N]; int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1}; bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m && snow[x][y] != '.'); } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < n; i++) cin >> snow[i]; deque<pair<int, int>> Q; Q.push_back({0, 0}); region[0][0] = 1; while (!Q.empty()) { auto [x, y] = Q.front(); Q.pop_front(); ans = max(ans, region[x][y]); for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (!valid(nx, ny) || region[nx][ny]) continue; if (snow[nx][ny] == snow[x][y]) { region[nx][ny] = region[x][y]; Q.push_front({nx, ny}); } else { region[nx][ny] = region[x][y] + 1; Q.push_back({nx, ny}); } } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...