제출 #827846

#제출 시각아이디문제언어결과실행 시간메모리
827846TobotisTracks in the Snow (BOI13_tracks)C++17
100 / 100
654 ms130612 KiB
#include <bits/stdc++.h> using namespace std; int dx[4]{0, 0, 1, -1}, dy[4]{1, -1, 0, 0}; int dist[4000][4000]; int w, h; bool inside(int i, int j) { return (0 <= i && i < w && 0 <= j && j < h); } int main() { cin >> w >> h; vector<string> mp(4000); for (int i = 0; i < w; i++) { cin >> mp[i]; } int ans = 1; deque<pair<int, int>> q; dist[0][0] = 1; q.push_back({0, 0}); while (!q.empty()) { auto [x, y] = q.front(); q.pop_front(); for (int i = 0; i < 4; i++) { int newx = x + dx[i]; int newy = y + dy[i]; if (inside(newx, newy) && dist[newx][newy] == 0 && mp[newx][newy] != '.') { if (mp[newx][newy] == mp[x][y]) { dist[newx][newy] = dist[x][y]; q.push_front({newx, newy}); } else { dist[newx][newy] = dist[x][y] + 1; ans = max(ans, dist[newx][newy]); q.push_back({newx, newy}); } } } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...