# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1018393 |
2024-07-09T22:23:05 Z |
cryptobunny |
Mecho (IOI09_mecho) |
C++14 |
|
491 ms |
18584 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, s, mx, my;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool check(int t, vector<vector<char>> grid, vector<vector<int>> btime) {
priority_queue<pair<int, pair<int, int>>> q;
q.push({0, {mx, my}});
vector<vector<int>> dist(n, vector<int>(n, 0x3f3f3f3f));
dist[mx][my] = 0;
while (!q.empty()) {
auto tp = q.top();
q.pop();
if (grid[tp.second.first][tp.second.second] == 'D') {
return true;
}
for (int i = 0; i < 4; i++) {
int nx = dx[i] + tp.second.first;
int ny = dy[i] + tp.second.second;
if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
if (grid[nx][ny] == 'T' || (btime[nx][ny] - t) * s <= -tp.first) continue;
if (dist[nx][ny] > 1 - tp.first) {
dist[nx][ny] = 1 - tp.first;
q.push({tp.first - 1, {nx, ny}});
}
}
}
return false;
}
signed main() {
cin >> n >> s;
vector<vector<char>> grid(n, vector<char>(n));
priority_queue<pair<int, pair<int, int>>> q;
vector<vector<int>> btime(n, vector<int>(n, 0x3f3f3f3f));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'H') {
btime[i][j] = 0;
q.push({0, {i, j}});
}
if (grid[i][j] == 'M') mx = i, my = j;
}
}
while (!q.empty()) {
auto tp = q.top();
q.pop();
if (btime[tp.second.first][tp.second.second] != -tp.first) continue;
for (int i = 0; i < 4; i++) {
int nx = dx[i] + tp.second.first;
int ny = dy[i] + tp.second.second;
if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
if (grid[nx][ny] != 'G' && grid[nx][ny] != 'M') continue;
if (-tp.first + 1 < btime[nx][ny]) {
btime[nx][ny] = 1 - tp.first;
q.push({-1 + tp.first, {nx, ny}});
}
}
}
int l = 0;
int r = 1e9 + 1;
while (l != r) {
int mid = (l + r + 1)/2;
if (check(mid, grid, btime)) {
l = mid;
}
else {
r = mid - 1;
}
}
cout << l << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
356 ms |
17892 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
612 KB |
Output isn't correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Correct |
0 ms |
424 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Incorrect |
18 ms |
3784 KB |
Output isn't correct |
34 |
Correct |
19 ms |
3856 KB |
Output is correct |
35 |
Correct |
73 ms |
3840 KB |
Output is correct |
36 |
Incorrect |
29 ms |
4872 KB |
Output isn't correct |
37 |
Correct |
24 ms |
4796 KB |
Output is correct |
38 |
Correct |
100 ms |
4804 KB |
Output is correct |
39 |
Incorrect |
37 ms |
6040 KB |
Output isn't correct |
40 |
Correct |
42 ms |
6044 KB |
Output is correct |
41 |
Correct |
127 ms |
5904 KB |
Output is correct |
42 |
Incorrect |
45 ms |
7252 KB |
Output isn't correct |
43 |
Correct |
39 ms |
7232 KB |
Output is correct |
44 |
Correct |
160 ms |
7252 KB |
Output is correct |
45 |
Incorrect |
53 ms |
8684 KB |
Output isn't correct |
46 |
Correct |
50 ms |
8696 KB |
Output is correct |
47 |
Correct |
201 ms |
8692 KB |
Output is correct |
48 |
Incorrect |
65 ms |
10172 KB |
Output isn't correct |
49 |
Correct |
68 ms |
10212 KB |
Output is correct |
50 |
Correct |
254 ms |
10156 KB |
Output is correct |
51 |
Incorrect |
76 ms |
11884 KB |
Output isn't correct |
52 |
Correct |
67 ms |
11820 KB |
Output is correct |
53 |
Correct |
326 ms |
11868 KB |
Output is correct |
54 |
Incorrect |
92 ms |
13608 KB |
Output isn't correct |
55 |
Correct |
98 ms |
13608 KB |
Output is correct |
56 |
Correct |
351 ms |
13676 KB |
Output is correct |
57 |
Incorrect |
109 ms |
15712 KB |
Output isn't correct |
58 |
Correct |
90 ms |
15756 KB |
Output is correct |
59 |
Correct |
415 ms |
15632 KB |
Output is correct |
60 |
Incorrect |
118 ms |
17676 KB |
Output isn't correct |
61 |
Correct |
129 ms |
17628 KB |
Output is correct |
62 |
Correct |
491 ms |
17672 KB |
Output is correct |
63 |
Correct |
299 ms |
17724 KB |
Output is correct |
64 |
Correct |
465 ms |
17596 KB |
Output is correct |
65 |
Correct |
455 ms |
17612 KB |
Output is correct |
66 |
Incorrect |
376 ms |
17620 KB |
Output isn't correct |
67 |
Incorrect |
319 ms |
17664 KB |
Output isn't correct |
68 |
Correct |
191 ms |
17844 KB |
Output is correct |
69 |
Correct |
200 ms |
17780 KB |
Output is correct |
70 |
Correct |
198 ms |
17748 KB |
Output is correct |
71 |
Correct |
178 ms |
17704 KB |
Output is correct |
72 |
Incorrect |
179 ms |
17716 KB |
Output isn't correct |
73 |
Incorrect |
190 ms |
18436 KB |
Output isn't correct |
74 |
Correct |
272 ms |
18336 KB |
Output is correct |
75 |
Correct |
284 ms |
18428 KB |
Output is correct |
76 |
Correct |
277 ms |
18584 KB |
Output is correct |
77 |
Correct |
294 ms |
18396 KB |
Output is correct |
78 |
Incorrect |
310 ms |
18432 KB |
Output isn't correct |
79 |
Correct |
260 ms |
18264 KB |
Output is correct |
80 |
Correct |
272 ms |
18348 KB |
Output is correct |
81 |
Correct |
276 ms |
18404 KB |
Output is correct |
82 |
Correct |
265 ms |
18372 KB |
Output is correct |
83 |
Correct |
321 ms |
18272 KB |
Output is correct |
84 |
Correct |
304 ms |
18196 KB |
Output is correct |
85 |
Correct |
293 ms |
18220 KB |
Output is correct |
86 |
Correct |
335 ms |
18344 KB |
Output is correct |
87 |
Correct |
302 ms |
18256 KB |
Output is correct |
88 |
Correct |
319 ms |
18104 KB |
Output is correct |
89 |
Correct |
329 ms |
18064 KB |
Output is correct |
90 |
Correct |
334 ms |
18104 KB |
Output is correct |
91 |
Correct |
329 ms |
18116 KB |
Output is correct |
92 |
Correct |
330 ms |
18044 KB |
Output is correct |