Submission #550465

#TimeUsernameProblemLanguageResultExecution timeMemory
550465JomnoiMecho (IOI09_mecho)C++17
11 / 100
153 ms6300 KiB
#include <bits/stdc++.h> #define DEBUG false using namespace std; const int MAX_N = 810; const int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; char s[MAX_N][MAX_N]; int db[MAX_N][MAX_N], dm[MAX_N][MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, S; cin >> N >> S; S++; for(int i = 1; i <= N; i++) { cin >> (s[i] + 1); } int sx, sy, ex, ey; queue <pair <int, int>> q; for(int i = 1; i <= N; i++) { for(int j = 1; j <= N; j++) { db[i][j] = -1; if(s[i][j] == 'H') { db[i][j] = 0; q.emplace(i, j); } else if(s[i][j] == 'M') { sx = i, sy = j; } else if(s[i][j] == 'D') { ex = i, ey = j; } } } while(!q.empty()) { auto [ux, uy] = q.front(); q.pop(); for(int i = 0; i < 4; i++) { int vx = ux + d[i][0], vy = uy + d[i][1]; if(vx < 1 or vx > N or vy < 1 or vy > N or s[vx][vy] == 'T' or s[vx][vy] == 'D' or db[vx][vy] != -1) { continue; } db[vx][vy] = db[ux][uy] + 1; q.emplace(vx, vy); } } int l = 0, r = 1e6, ans = -1; while(l <= r) { int mid = (l + r) / 2; for(int i = 1; i <= N; i++) { for(int j = 1; j <= N; j++) { dm[i][j] = -1; } } queue <pair <int, int>> q; q.emplace(sx, sy); dm[sx][sy] = 0; while(!q.empty()) { auto [ux, uy] = q.front(); q.pop(); for(int i = 0; i < 4; i++) { int vx = ux + d[i][0], vy = uy + d[i][1]; if(vx < 1 or vx > N or vy < 1 or vy > N or s[vx][vy] == 'T' or dm[vx][vy] != -1) { continue; } if(db[vx][vy] != -1 and (dm[ux][uy] + 1) / S >= db[vx][vy] - mid) { continue; } dm[vx][vy] = dm[ux][uy] + 1; q.emplace(vx, vy); } } if(dm[ex][ey] == -1) { r = mid - 1; } else { l = mid + 1; ans = mid; } } cout << ans; return 0; }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:84:21: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
   84 |         if(dm[ex][ey] == -1) {
      |            ~~~~~~~~~^
mecho.cpp:84:21: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...