# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
495711 |
2021-12-20T03:25:58 Z |
chenwz |
Mecho (IOI09_mecho) |
C++11 |
|
180 ms |
21600 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19916 KB |
Output is correct |
2 |
Correct |
9 ms |
19916 KB |
Output is correct |
3 |
Correct |
9 ms |
19948 KB |
Output is correct |
4 |
Correct |
9 ms |
19968 KB |
Output is correct |
5 |
Correct |
10 ms |
19908 KB |
Output is correct |
6 |
Correct |
8 ms |
19916 KB |
Output is correct |
7 |
Correct |
82 ms |
21316 KB |
Output is correct |
8 |
Correct |
8 ms |
19916 KB |
Output is correct |
9 |
Correct |
11 ms |
19964 KB |
Output is correct |
10 |
Correct |
13 ms |
19960 KB |
Output is correct |
11 |
Correct |
9 ms |
19916 KB |
Output is correct |
12 |
Correct |
9 ms |
20044 KB |
Output is correct |
13 |
Correct |
9 ms |
19916 KB |
Output is correct |
14 |
Correct |
9 ms |
19960 KB |
Output is correct |
15 |
Correct |
10 ms |
19916 KB |
Output is correct |
16 |
Correct |
9 ms |
19916 KB |
Output is correct |
17 |
Correct |
11 ms |
19992 KB |
Output is correct |
18 |
Correct |
9 ms |
19924 KB |
Output is correct |
19 |
Correct |
8 ms |
19968 KB |
Output is correct |
20 |
Correct |
9 ms |
19972 KB |
Output is correct |
21 |
Correct |
9 ms |
19916 KB |
Output is correct |
22 |
Correct |
10 ms |
20044 KB |
Output is correct |
23 |
Correct |
9 ms |
20004 KB |
Output is correct |
24 |
Correct |
8 ms |
19916 KB |
Output is correct |
25 |
Correct |
10 ms |
19988 KB |
Output is correct |
26 |
Correct |
9 ms |
19996 KB |
Output is correct |
27 |
Correct |
9 ms |
20044 KB |
Output is correct |
28 |
Correct |
11 ms |
19916 KB |
Output is correct |
29 |
Correct |
10 ms |
19916 KB |
Output is correct |
30 |
Correct |
10 ms |
20044 KB |
Output is correct |
31 |
Correct |
11 ms |
20016 KB |
Output is correct |
32 |
Correct |
11 ms |
19924 KB |
Output is correct |
33 |
Correct |
12 ms |
20172 KB |
Output is correct |
34 |
Correct |
14 ms |
20224 KB |
Output is correct |
35 |
Correct |
27 ms |
20256 KB |
Output is correct |
36 |
Correct |
12 ms |
20292 KB |
Output is correct |
37 |
Correct |
12 ms |
20296 KB |
Output is correct |
38 |
Correct |
35 ms |
20348 KB |
Output is correct |
39 |
Correct |
16 ms |
20312 KB |
Output is correct |
40 |
Correct |
14 ms |
20344 KB |
Output is correct |
41 |
Correct |
47 ms |
20424 KB |
Output is correct |
42 |
Correct |
14 ms |
20428 KB |
Output is correct |
43 |
Correct |
16 ms |
20412 KB |
Output is correct |
44 |
Correct |
50 ms |
20520 KB |
Output is correct |
45 |
Correct |
15 ms |
20592 KB |
Output is correct |
46 |
Correct |
17 ms |
20556 KB |
Output is correct |
47 |
Correct |
56 ms |
20596 KB |
Output is correct |
48 |
Correct |
15 ms |
20736 KB |
Output is correct |
49 |
Correct |
15 ms |
20668 KB |
Output is correct |
50 |
Correct |
96 ms |
20756 KB |
Output is correct |
51 |
Correct |
19 ms |
20796 KB |
Output is correct |
52 |
Correct |
17 ms |
20760 KB |
Output is correct |
53 |
Correct |
76 ms |
20876 KB |
Output is correct |
54 |
Correct |
20 ms |
20932 KB |
Output is correct |
55 |
Correct |
16 ms |
20936 KB |
Output is correct |
56 |
Correct |
101 ms |
21012 KB |
Output is correct |
57 |
Correct |
20 ms |
21060 KB |
Output is correct |
58 |
Correct |
18 ms |
21124 KB |
Output is correct |
59 |
Correct |
103 ms |
21160 KB |
Output is correct |
60 |
Correct |
19 ms |
21244 KB |
Output is correct |
61 |
Correct |
18 ms |
21228 KB |
Output is correct |
62 |
Correct |
133 ms |
21336 KB |
Output is correct |
63 |
Correct |
131 ms |
21200 KB |
Output is correct |
64 |
Correct |
180 ms |
21248 KB |
Output is correct |
65 |
Correct |
142 ms |
21316 KB |
Output is correct |
66 |
Correct |
142 ms |
21304 KB |
Output is correct |
67 |
Correct |
143 ms |
21244 KB |
Output is correct |
68 |
Correct |
49 ms |
21328 KB |
Output is correct |
69 |
Correct |
49 ms |
21296 KB |
Output is correct |
70 |
Correct |
37 ms |
21264 KB |
Output is correct |
71 |
Correct |
45 ms |
21320 KB |
Output is correct |
72 |
Correct |
35 ms |
21320 KB |
Output is correct |
73 |
Correct |
32 ms |
21536 KB |
Output is correct |
74 |
Correct |
56 ms |
21600 KB |
Output is correct |
75 |
Correct |
71 ms |
21556 KB |
Output is correct |
76 |
Correct |
81 ms |
21572 KB |
Output is correct |
77 |
Correct |
79 ms |
21508 KB |
Output is correct |
78 |
Correct |
84 ms |
21452 KB |
Output is correct |
79 |
Correct |
51 ms |
21552 KB |
Output is correct |
80 |
Correct |
65 ms |
21480 KB |
Output is correct |
81 |
Correct |
103 ms |
21564 KB |
Output is correct |
82 |
Correct |
60 ms |
21500 KB |
Output is correct |
83 |
Correct |
83 ms |
21448 KB |
Output is correct |
84 |
Correct |
72 ms |
21556 KB |
Output is correct |
85 |
Correct |
83 ms |
21452 KB |
Output is correct |
86 |
Correct |
85 ms |
21512 KB |
Output is correct |
87 |
Correct |
75 ms |
21444 KB |
Output is correct |
88 |
Correct |
95 ms |
21464 KB |
Output is correct |
89 |
Correct |
86 ms |
21464 KB |
Output is correct |
90 |
Correct |
92 ms |
21348 KB |
Output is correct |
91 |
Correct |
86 ms |
21376 KB |
Output is correct |
92 |
Correct |
89 ms |
21468 KB |
Output is correct |