Submission #482105

#TimeUsernameProblemLanguageResultExecution timeMemory
482105nehasaneTracks in the Snow (BOI13_tracks)C++14
84.69 / 100
2086 ms149380 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_H = 4000; const int MAX_W = 4000; vector <string> meadow(MAX_H); bool diff_animal(int x, int y, int diffx, int diffy){ if (meadow[x][y] != meadow[x + diffx][y + diffy]) return true; return false; } int main() { int h, w; cin >> h >> w; for (int i = 0; i < h; i++) cin >> meadow[i]; priority_queue <tuple <int, int, int>> q; int dis[MAX_H][MAX_W]; bool visited[MAX_H][MAX_W]; for (int i = 0; i < MAX_H; i++){ for (int j = 0; j < MAX_W; j++){ dis[i][j] = INT_MAX; visited[i][j] = false; } } q.push({0, 0, 0}); dis[0][0] = 0; int ans = 0; while (!q.empty()){ int x = get<1>(q.top()), y = get<2>(q.top()); q.pop(); if (visited[x][y]) continue; visited[x][y] = true; //check up if (x > 0 && meadow[x-1][y] != '.'){ int d = diff_animal(x, y, -1, 0); if (dis[x-1][y] > dis[x][y] + d){ dis[x-1][y] = dis[x][y] + d; ans = max(ans, dis[x-1][y]); q.push({-dis[x-1][y], x-1, y}); } } //check down if (x < h-1 && meadow[x+1][y] != '.'){ int d = diff_animal(x, y, 1, 0); if (dis[x+1][y] > dis[x][y] + d){ dis[x+1][y] = dis[x][y] + d; ans = max(ans, dis[x+1][y]); q.push({-dis[x+1][y], x+1, y}); } } //check left if (y > 0 && meadow[x][y-1] != '.'){ int d = diff_animal(x, y, 0, -1); if (dis[x][y-1] > dis[x][y] + d){ dis[x][y-1] = dis[x][y] + d; ans = max(ans, dis[x][y-1]); q.push({-dis[x][y-1], x, y-1}); } } //check right if (y < w-1 && meadow[x][y+1] != '.'){ int d = diff_animal(x, y, 0, 1); if (dis[x][y+1] > dis[x][y] + d){ dis[x][y+1] = dis[x][y] + d; ans = max(ans, dis[x][y+1]); q.push({-dis[x][y+1], x, y+1}); } } } cout << ans+ 1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...