# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1002839 |
2024-06-19T20:27:43 Z |
Tob |
Mecho (IOI09_mecho) |
C++14 |
|
90 ms |
7496 KB |
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef pair <ll, ll> pii;
const int N = 807, inf = 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, S, stx, sty, enx, eny;
char mat[N][N];
int bee[N][N], bio[N][N];
int main () {
FIO;
cin >> n >> S;
vector <pii> v;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> mat[i][j];
if (mat[i][j] == 'M') stx = i, sty = j;
if (mat[i][j] == 'D') enx = i, eny = j;
if (mat[i][j] == 'H') v.pb({i, j});
}
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) bee[i][j] = inf;
for (int i = 0; i <= n+1; i++) bee[i][0] = bee[i][n+1] = bee[0][i] = bee[n+1][i] = -1;
queue <pii> q;
for (auto it : v) {
q.push(it);
bee[it.F][it.S] = 0;
}
while (!q.empty()) {
pii fr = q.front(); q.pop();
int x = fr.F, y = fr.S;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (bee[nx][ny] != inf) continue;
if (mat[nx][ny] == 'T' || mat[nx][ny] == 'D') continue;
bee[nx][ny] = bee[x][y] + 1;
q.push({nx, ny});
}
}
int lo = -1, hi = 1e8;
while (!q.empty()) q.pop();
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
if (mid >= bee[stx][sty]) {
hi = mid-1;
continue;
}
memset(bio, -1, sizeof bio);
for (int i = 0; i <= n+1; i++) bio[i][0] = bio[i][n+1] = bio[0][i] = bio[n+1][i] = -2;
bio[stx][sty] = 0;
q.push({stx, sty});
while (!q.empty()) {
pii fr = q.front(); q.pop();
int x = fr.F, y = fr.S;
int d = bio[x][y];
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (bio[nx][ny] != -1) continue;
if (mat[nx][ny] == 'T' || bee[nx][ny] <= mid+(d+1)/S) continue;
bio[nx][ny] = d + 1;
q.push({nx, ny});
}
}
if (bio[enx][eny] == -1) hi = mid-1;
else lo = mid;
}
cout << lo << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
37 ms |
6800 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
1 ms |
2908 KB |
Output is correct |
10 |
Correct |
1 ms |
2908 KB |
Output is correct |
11 |
Correct |
1 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3160 KB |
Output is correct |
14 |
Correct |
2 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
2908 KB |
Output is correct |
17 |
Correct |
1 ms |
2908 KB |
Output is correct |
18 |
Correct |
2 ms |
2908 KB |
Output is correct |
19 |
Correct |
1 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2908 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
2 ms |
3164 KB |
Output is correct |
23 |
Correct |
2 ms |
3164 KB |
Output is correct |
24 |
Correct |
2 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3164 KB |
Output is correct |
26 |
Correct |
2 ms |
3160 KB |
Output is correct |
27 |
Correct |
2 ms |
3160 KB |
Output is correct |
28 |
Correct |
1 ms |
3164 KB |
Output is correct |
29 |
Correct |
1 ms |
3164 KB |
Output is correct |
30 |
Correct |
2 ms |
3300 KB |
Output is correct |
31 |
Correct |
2 ms |
3280 KB |
Output is correct |
32 |
Correct |
2 ms |
3164 KB |
Output is correct |
33 |
Correct |
6 ms |
4440 KB |
Output is correct |
34 |
Correct |
5 ms |
4440 KB |
Output is correct |
35 |
Correct |
11 ms |
4440 KB |
Output is correct |
36 |
Correct |
5 ms |
4700 KB |
Output is correct |
37 |
Correct |
5 ms |
4700 KB |
Output is correct |
38 |
Correct |
16 ms |
4700 KB |
Output is correct |
39 |
Correct |
6 ms |
4956 KB |
Output is correct |
40 |
Correct |
5 ms |
5000 KB |
Output is correct |
41 |
Correct |
20 ms |
4956 KB |
Output is correct |
42 |
Correct |
7 ms |
5208 KB |
Output is correct |
43 |
Correct |
6 ms |
5216 KB |
Output is correct |
44 |
Correct |
24 ms |
5212 KB |
Output is correct |
45 |
Correct |
8 ms |
5464 KB |
Output is correct |
46 |
Correct |
7 ms |
5468 KB |
Output is correct |
47 |
Correct |
26 ms |
5464 KB |
Output is correct |
48 |
Correct |
8 ms |
5724 KB |
Output is correct |
49 |
Correct |
9 ms |
5500 KB |
Output is correct |
50 |
Correct |
31 ms |
5724 KB |
Output is correct |
51 |
Correct |
10 ms |
5764 KB |
Output is correct |
52 |
Correct |
10 ms |
5980 KB |
Output is correct |
53 |
Correct |
40 ms |
5980 KB |
Output is correct |
54 |
Correct |
11 ms |
6232 KB |
Output is correct |
55 |
Correct |
11 ms |
6236 KB |
Output is correct |
56 |
Correct |
41 ms |
6236 KB |
Output is correct |
57 |
Correct |
11 ms |
6532 KB |
Output is correct |
58 |
Correct |
12 ms |
6528 KB |
Output is correct |
59 |
Correct |
52 ms |
6528 KB |
Output is correct |
60 |
Correct |
14 ms |
6744 KB |
Output is correct |
61 |
Correct |
12 ms |
6748 KB |
Output is correct |
62 |
Correct |
54 ms |
6828 KB |
Output is correct |
63 |
Correct |
57 ms |
6748 KB |
Output is correct |
64 |
Correct |
80 ms |
6748 KB |
Output is correct |
65 |
Correct |
90 ms |
6748 KB |
Output is correct |
66 |
Correct |
75 ms |
6996 KB |
Output is correct |
67 |
Correct |
69 ms |
6796 KB |
Output is correct |
68 |
Correct |
29 ms |
6744 KB |
Output is correct |
69 |
Correct |
28 ms |
6740 KB |
Output is correct |
70 |
Correct |
24 ms |
6748 KB |
Output is correct |
71 |
Correct |
23 ms |
6636 KB |
Output is correct |
72 |
Correct |
20 ms |
6632 KB |
Output is correct |
73 |
Correct |
21 ms |
7236 KB |
Output is correct |
74 |
Correct |
34 ms |
7348 KB |
Output is correct |
75 |
Correct |
36 ms |
7204 KB |
Output is correct |
76 |
Correct |
36 ms |
7260 KB |
Output is correct |
77 |
Correct |
37 ms |
7252 KB |
Output is correct |
78 |
Correct |
42 ms |
7260 KB |
Output is correct |
79 |
Correct |
35 ms |
7260 KB |
Output is correct |
80 |
Correct |
35 ms |
7096 KB |
Output is correct |
81 |
Correct |
39 ms |
7164 KB |
Output is correct |
82 |
Correct |
37 ms |
7496 KB |
Output is correct |
83 |
Correct |
36 ms |
7000 KB |
Output is correct |
84 |
Correct |
37 ms |
6996 KB |
Output is correct |
85 |
Correct |
36 ms |
7260 KB |
Output is correct |
86 |
Correct |
41 ms |
7020 KB |
Output is correct |
87 |
Correct |
41 ms |
7004 KB |
Output is correct |
88 |
Correct |
40 ms |
6996 KB |
Output is correct |
89 |
Correct |
45 ms |
7128 KB |
Output is correct |
90 |
Correct |
45 ms |
7004 KB |
Output is correct |
91 |
Correct |
45 ms |
6992 KB |
Output is correct |
92 |
Correct |
45 ms |
7004 KB |
Output is correct |