# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
943493 |
2024-03-11T14:24:18 Z |
myst6 |
Mecho (IOI09_mecho) |
C++17 |
|
895 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
int di[4] = {1, -1, 0, 0};
int dj[4] = {0, 0, 1, -1};
const int maxn = 800;
char grid[maxn][maxn];
int dist[maxn][maxn];
int dist2[maxn][maxn];
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, S;
cin >> N >> S;
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
cin >> grid[i][j];
dist[i][j] = inf;
}
}
queue<int> Q;
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
if (grid[i][j] == 'H') {
dist[i][j] = 0;
Q.push(i*N+j);
}
}
}
while (Q.size()) {
int x = Q.front(); Q.pop();
int i = x/N, j = x%N;
for (int k=0; k<4; k++) {
int i2 = i + di[k];
int j2 = j + dj[k];
if (i2 < 0 || j2 < 0 || i2 >= N || j2 >= N) continue;
if (grid[i2][j2] != 'G') continue;
if (dist[i2][j2] <= dist[i][j]) continue;
dist[i2][j2] = dist[i][j] + 1;
Q.push(i2*N+j2);
}
}
pair<int,int> begin, end;
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
if (grid[i][j] == 'M') {
begin = {i, j};
} else if (grid[i][j] == 'D') {
end = {i, j};
}
}
}
int lo = 0, hi = 1 << 30, ans = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
// mid = number of steps the bees have progressed already
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
dist2[i][j] = inf;
}
}
dist2[begin.first][begin.second] = 0;
Q.push(begin.first*N+begin.second);
while (Q.size()) {
auto x = Q.front(); Q.pop();
int i = x/N, j = x%N;
for (int k=0; k<4; k++) {
int i2 = i + di[k];
int j2 = j + dj[k];
if (i2 < 0 || j2 < 0 || i2 >= N || j2 >= N) continue;
if (grid[i2][j2] != 'G' && grid[i2][j2] != 'D') continue;
if (dist2[i2][j2] <= dist2[i][j]) continue;
int T = mid + (dist2[i][j] + 1) / S;
if (dist[i2][j2] <= T) continue;
dist2[i2][j2] = dist2[i][j] + 1;
Q.push(i2*N+j2);
}
}
if (dist2[end.first][end.second] == inf) {
hi = mid - 1;
} else {
ans = mid;
lo = mid + 1;
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2564 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Runtime error |
398 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
13 |
Runtime error |
650 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
671 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
5 ms |
4956 KB |
Output is correct |
34 |
Correct |
6 ms |
4956 KB |
Output is correct |
35 |
Runtime error |
359 ms |
65536 KB |
Execution killed with signal 9 |
36 |
Correct |
7 ms |
4956 KB |
Output is correct |
37 |
Correct |
6 ms |
4956 KB |
Output is correct |
38 |
Runtime error |
354 ms |
65536 KB |
Execution killed with signal 9 |
39 |
Correct |
7 ms |
4956 KB |
Output is correct |
40 |
Correct |
7 ms |
5100 KB |
Output is correct |
41 |
Runtime error |
344 ms |
65536 KB |
Execution killed with signal 9 |
42 |
Correct |
9 ms |
5136 KB |
Output is correct |
43 |
Correct |
10 ms |
4956 KB |
Output is correct |
44 |
Runtime error |
356 ms |
65536 KB |
Execution killed with signal 9 |
45 |
Correct |
10 ms |
4956 KB |
Output is correct |
46 |
Correct |
10 ms |
4952 KB |
Output is correct |
47 |
Runtime error |
358 ms |
65536 KB |
Execution killed with signal 9 |
48 |
Correct |
12 ms |
5212 KB |
Output is correct |
49 |
Correct |
13 ms |
5116 KB |
Output is correct |
50 |
Runtime error |
376 ms |
65536 KB |
Execution killed with signal 9 |
51 |
Correct |
14 ms |
5468 KB |
Output is correct |
52 |
Correct |
15 ms |
5464 KB |
Output is correct |
53 |
Runtime error |
395 ms |
65536 KB |
Execution killed with signal 9 |
54 |
Correct |
20 ms |
5720 KB |
Output is correct |
55 |
Correct |
19 ms |
5464 KB |
Output is correct |
56 |
Runtime error |
355 ms |
65536 KB |
Execution killed with signal 9 |
57 |
Correct |
17 ms |
5724 KB |
Output is correct |
58 |
Correct |
19 ms |
5724 KB |
Output is correct |
59 |
Runtime error |
358 ms |
65536 KB |
Execution killed with signal 9 |
60 |
Correct |
22 ms |
6068 KB |
Output is correct |
61 |
Correct |
22 ms |
5976 KB |
Output is correct |
62 |
Runtime error |
373 ms |
65536 KB |
Execution killed with signal 9 |
63 |
Correct |
114 ms |
6072 KB |
Output is correct |
64 |
Correct |
156 ms |
5980 KB |
Output is correct |
65 |
Correct |
151 ms |
6068 KB |
Output is correct |
66 |
Correct |
114 ms |
5976 KB |
Output is correct |
67 |
Correct |
106 ms |
5972 KB |
Output is correct |
68 |
Correct |
48 ms |
5980 KB |
Output is correct |
69 |
Correct |
46 ms |
5968 KB |
Output is correct |
70 |
Correct |
46 ms |
5976 KB |
Output is correct |
71 |
Correct |
33 ms |
5976 KB |
Output is correct |
72 |
Incorrect |
38 ms |
5980 KB |
Output isn't correct |
73 |
Runtime error |
895 ms |
65536 KB |
Execution killed with signal 9 |
74 |
Runtime error |
814 ms |
65536 KB |
Execution killed with signal 9 |
75 |
Runtime error |
840 ms |
65536 KB |
Execution killed with signal 9 |
76 |
Runtime error |
844 ms |
65536 KB |
Execution killed with signal 9 |
77 |
Runtime error |
835 ms |
65536 KB |
Execution killed with signal 9 |
78 |
Runtime error |
674 ms |
65536 KB |
Execution killed with signal 9 |
79 |
Runtime error |
687 ms |
65536 KB |
Execution killed with signal 9 |
80 |
Runtime error |
643 ms |
65536 KB |
Execution killed with signal 9 |
81 |
Runtime error |
642 ms |
65536 KB |
Execution killed with signal 9 |
82 |
Runtime error |
640 ms |
65536 KB |
Execution killed with signal 9 |
83 |
Runtime error |
537 ms |
65536 KB |
Execution killed with signal 9 |
84 |
Runtime error |
565 ms |
65536 KB |
Execution killed with signal 9 |
85 |
Runtime error |
532 ms |
65536 KB |
Execution killed with signal 9 |
86 |
Runtime error |
531 ms |
65536 KB |
Execution killed with signal 9 |
87 |
Runtime error |
537 ms |
65536 KB |
Execution killed with signal 9 |
88 |
Runtime error |
484 ms |
65536 KB |
Execution killed with signal 9 |
89 |
Runtime error |
453 ms |
65536 KB |
Execution killed with signal 9 |
90 |
Runtime error |
441 ms |
65536 KB |
Execution killed with signal 9 |
91 |
Runtime error |
442 ms |
65536 KB |
Execution killed with signal 9 |
92 |
Runtime error |
456 ms |
65536 KB |
Execution killed with signal 9 |