Submission #495711

#TimeUsernameProblemLanguageResultExecution timeMemory
495711chenwzMecho (IOI09_mecho)C++11
100 / 100
180 ms21600 KiB
#include <bits/stdc++.h> using namespace std; const int NN = 2000 + 4, DX[4] = {1, -1, 0, 0}, DY[4] = {0, 0, 1, -1}; #define _for(i, a, b) for (int i = (a); i < (int)(b); ++i) string G[NN]; int N, S, D[NN][NN]; bool Vis[NN][NN]; struct Point { int x, y; }; bool check(const Point& st, int delay) { if (delay * S >= D[st.x][st.y]) return false; queue<pair<int, Point> > Q; memset(Vis, 0, sizeof(Vis)), Q.push({delay * S, st}), Vis[st.x][st.y] = true; while (!Q.empty()) { auto p = Q.front(); Q.pop(); int d = p.first, x = p.second.x, y = p.second.y; if (G[x][y] == 'D') return true; _for(i, 0, 4) { int nx = x + DX[i], ny = y + DY[i]; if (nx < 0 || nx >= N || ny < 0 || ny >= N || G[nx][ny] == 'T' || (d + 1) >= D[nx][ny] || Vis[nx][ny]) continue; Q.push({d + 1, {nx, ny}}), Vis[nx][ny] = true; } } return false; } int main() { ios::sync_with_stdio(false), cin.tie(0); cin >> N >> S; queue<Point> Q; Point Honey, Home; memset(D, -1, sizeof(D)); _for(i, 0, N) { cin >> G[i]; _for(j, 0, N) { char& c = G[i][j]; if (c == 'H') Q.push({i, j}), D[i][j] = 0; if (c == 'M') Honey = {i, j}, c = 'G'; if (c == 'D') Home = {i, j}; } } while (!Q.empty()) { Point p = Q.front(); Q.pop(); _for(i, 0, 4) { int nx = p.x + DX[i], ny = p.y + DY[i]; if (nx < 0 || nx >= N || ny < 0 || ny >= N || G[nx][ny] != 'G' || D[nx][ny] != -1) continue; D[nx][ny] = D[p.x][p.y] + S, Q.push({nx, ny}); } } D[Home.x][Home.y] = N * N * S; int L = -1, R = 2 * N * N; while (L + 1 < R) { int mid = (L + R) / 2; (check(Honey, mid) ? L : R) = mid; } cout << L << endl; return 0; }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:56:21: warning: 'Home.Point::x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |   D[Home.x][Home.y] = N * N * S;
      |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
mecho.cpp:56:21: warning: 'Home.Point::y' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...