# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
771014 |
2023-07-02T10:44:33 Z |
ind1v |
Mecho (IOI09_mecho) |
C++11 |
|
157 ms |
9484 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 805;
const int dI[4] = {-1, 0, +1, 0};
const int dJ[4] = {0, +1, 0, -1};
int n, s;
char a[N][N];
long long d[N][N];
int f[N][N];
bool can[N][N];
int mx, my, dx, dy;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> s;
memset(d, 0x3f, sizeof(d));
memset(f, 0x3f, sizeof(f));
queue<pair<int, int>> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] == 'H') {
d[i][j] = 0;
q.push({i, j});
} else if (a[i][j] == 'M') {
mx = i;
my = j;
} else if (a[i][j] == 'D') {
dx = i;
dy = j;
}
}
}
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop();
for (int dir = 0; dir < 4; dir++) {
int nx = x + dI[dir];
int ny = y + dJ[dir];
if (1 <= nx && nx <= n && 1 <= ny && ny <= n && a[nx][ny] != 'D' && a[nx][ny] != 'T' && d[nx][ny] > d[x][y] + 1) {
d[nx][ny] = d[x][y] + 1;
q.push({nx, ny});
}
}
}
int l = 0, r = n * n, ans = -1;
while (l <= r) {
int m = (l + r) >> 1;
memset(f, 0x3f, sizeof(f));
memset(can, false, sizeof(can));
queue<pair<int, int>> q;
if (m < d[mx][my]) {
f[mx][my] = 0;
can[mx][my] = true;
q.push({mx, my});
}
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop();
for (int dir = 0; dir < 4; dir++) {
int nx = x + dI[dir];
int ny = y + dJ[dir];
if (1 <= nx && nx <= n && 1 <= ny && ny <= n && a[nx][ny] != 'T' && f[nx][ny] > f[x][y] + 1 && (f[x][y] + 1) / s + m < d[nx][ny] && !can[nx][ny]) {
f[nx][ny] = f[x][y] + 1;
can[nx][ny] = true;
q.push({nx, ny});
}
}
}
if (can[dx][dy]) {
ans = m;
l = m + 1;
} else {
r = m - 1;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8532 KB |
Output is correct |
2 |
Correct |
4 ms |
8532 KB |
Output is correct |
3 |
Correct |
4 ms |
8532 KB |
Output is correct |
4 |
Correct |
4 ms |
8532 KB |
Output is correct |
5 |
Correct |
4 ms |
8532 KB |
Output is correct |
6 |
Correct |
4 ms |
8532 KB |
Output is correct |
7 |
Correct |
71 ms |
9288 KB |
Output is correct |
8 |
Correct |
4 ms |
8532 KB |
Output is correct |
9 |
Correct |
3 ms |
8532 KB |
Output is correct |
10 |
Correct |
3 ms |
8532 KB |
Output is correct |
11 |
Correct |
4 ms |
8532 KB |
Output is correct |
12 |
Correct |
4 ms |
8532 KB |
Output is correct |
13 |
Correct |
4 ms |
8532 KB |
Output is correct |
14 |
Correct |
4 ms |
8532 KB |
Output is correct |
15 |
Correct |
4 ms |
8532 KB |
Output is correct |
16 |
Correct |
4 ms |
8500 KB |
Output is correct |
17 |
Correct |
4 ms |
8532 KB |
Output is correct |
18 |
Correct |
4 ms |
8532 KB |
Output is correct |
19 |
Correct |
4 ms |
8528 KB |
Output is correct |
20 |
Correct |
4 ms |
8532 KB |
Output is correct |
21 |
Correct |
4 ms |
8628 KB |
Output is correct |
22 |
Correct |
5 ms |
8660 KB |
Output is correct |
23 |
Correct |
4 ms |
8532 KB |
Output is correct |
24 |
Correct |
4 ms |
8532 KB |
Output is correct |
25 |
Correct |
5 ms |
8616 KB |
Output is correct |
26 |
Correct |
4 ms |
8532 KB |
Output is correct |
27 |
Correct |
4 ms |
8532 KB |
Output is correct |
28 |
Correct |
4 ms |
8532 KB |
Output is correct |
29 |
Correct |
4 ms |
8620 KB |
Output is correct |
30 |
Correct |
5 ms |
8532 KB |
Output is correct |
31 |
Correct |
4 ms |
8532 KB |
Output is correct |
32 |
Correct |
4 ms |
8532 KB |
Output is correct |
33 |
Correct |
7 ms |
8848 KB |
Output is correct |
34 |
Correct |
7 ms |
8788 KB |
Output is correct |
35 |
Correct |
21 ms |
8788 KB |
Output is correct |
36 |
Correct |
8 ms |
8788 KB |
Output is correct |
37 |
Correct |
8 ms |
8788 KB |
Output is correct |
38 |
Correct |
25 ms |
8788 KB |
Output is correct |
39 |
Correct |
11 ms |
8916 KB |
Output is correct |
40 |
Correct |
11 ms |
8916 KB |
Output is correct |
41 |
Correct |
33 ms |
8920 KB |
Output is correct |
42 |
Correct |
10 ms |
8916 KB |
Output is correct |
43 |
Correct |
11 ms |
8916 KB |
Output is correct |
44 |
Correct |
39 ms |
8952 KB |
Output is correct |
45 |
Correct |
14 ms |
8916 KB |
Output is correct |
46 |
Correct |
12 ms |
8916 KB |
Output is correct |
47 |
Correct |
54 ms |
8976 KB |
Output is correct |
48 |
Correct |
13 ms |
8968 KB |
Output is correct |
49 |
Correct |
13 ms |
9044 KB |
Output is correct |
50 |
Correct |
52 ms |
8932 KB |
Output is correct |
51 |
Correct |
15 ms |
8968 KB |
Output is correct |
52 |
Correct |
15 ms |
8968 KB |
Output is correct |
53 |
Correct |
71 ms |
9108 KB |
Output is correct |
54 |
Correct |
18 ms |
9100 KB |
Output is correct |
55 |
Correct |
16 ms |
9004 KB |
Output is correct |
56 |
Correct |
75 ms |
9112 KB |
Output is correct |
57 |
Correct |
18 ms |
9080 KB |
Output is correct |
58 |
Correct |
23 ms |
9044 KB |
Output is correct |
59 |
Correct |
85 ms |
9052 KB |
Output is correct |
60 |
Correct |
20 ms |
9084 KB |
Output is correct |
61 |
Correct |
20 ms |
9136 KB |
Output is correct |
62 |
Correct |
97 ms |
9152 KB |
Output is correct |
63 |
Correct |
85 ms |
9184 KB |
Output is correct |
64 |
Correct |
157 ms |
9184 KB |
Output is correct |
65 |
Correct |
117 ms |
9172 KB |
Output is correct |
66 |
Correct |
97 ms |
9172 KB |
Output is correct |
67 |
Correct |
93 ms |
9188 KB |
Output is correct |
68 |
Correct |
40 ms |
9108 KB |
Output is correct |
69 |
Correct |
39 ms |
9172 KB |
Output is correct |
70 |
Correct |
30 ms |
9112 KB |
Output is correct |
71 |
Correct |
36 ms |
9104 KB |
Output is correct |
72 |
Correct |
27 ms |
9164 KB |
Output is correct |
73 |
Correct |
29 ms |
9484 KB |
Output is correct |
74 |
Correct |
48 ms |
9472 KB |
Output is correct |
75 |
Correct |
62 ms |
9452 KB |
Output is correct |
76 |
Correct |
53 ms |
9464 KB |
Output is correct |
77 |
Correct |
49 ms |
9356 KB |
Output is correct |
78 |
Correct |
62 ms |
9420 KB |
Output is correct |
79 |
Correct |
43 ms |
9324 KB |
Output is correct |
80 |
Correct |
49 ms |
9440 KB |
Output is correct |
81 |
Correct |
58 ms |
9444 KB |
Output is correct |
82 |
Correct |
54 ms |
9448 KB |
Output is correct |
83 |
Correct |
73 ms |
9396 KB |
Output is correct |
84 |
Correct |
57 ms |
9396 KB |
Output is correct |
85 |
Correct |
63 ms |
9396 KB |
Output is correct |
86 |
Correct |
60 ms |
9292 KB |
Output is correct |
87 |
Correct |
76 ms |
9396 KB |
Output is correct |
88 |
Correct |
64 ms |
9348 KB |
Output is correct |
89 |
Correct |
65 ms |
9348 KB |
Output is correct |
90 |
Correct |
77 ms |
9300 KB |
Output is correct |
91 |
Correct |
72 ms |
9364 KB |
Output is correct |
92 |
Correct |
75 ms |
9244 KB |
Output is correct |