제출 #1272800

#제출 시각아이디문제언어결과실행 시간메모리
1272800alexocodeTracks in the Snow (BOI13_tracks)C++20
100 / 100
358 ms118788 KiB
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <map> #include <utility> #include <deque> #include <unordered_map> using namespace std; using vi = vector<int>; typedef long long ll; typedef unsigned long long ull; #define pb push_back const ll MOD = 1e9 + 7; const ll INF = 1e9; int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1}; int depth[4000][4000]; string snow[4000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> snow[i]; } deque<pair<int ,int>> q; q.push_back({0, 0}); depth[0][0] = 1; int ans = 0; while (!q.empty()) { auto p = q.front(); int x = p.first, y = p.second; ans = max(ans, depth[x][y]); q.pop_front(); for (int i = 0; i < sizeof(dx) / sizeof(dx[0]); i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx >= n || ny < 0 || ny >= m || depth[nx][ny] != 0 || snow[nx][ny] == '.') continue; if (snow[x][y] == snow[nx][ny]) { depth[nx][ny] = depth[x][y]; q.push_front({nx, ny}); } else { depth[nx][ny] = depth[x][y] + 1; q.push_back({nx, ny}); } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...