# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
950866 |
2024-03-20T20:52:52 Z |
blackslex |
Mecho (IOI09_mecho) |
C++17 |
|
185 ms |
6492 KB |
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using tp = tuple<int, int, int>;
const int cd[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int n, s, sx, sy, tx, ty;
int main() {
scanf("%d %d", &n, &s);
vector<string> c(n + 5);
for (int i = 1; i <= n; i++) cin >> c[i], c[i] = " " + c[i];
queue<pii> q;
vector<vector<int>> d(n + 5, vector<int>(n + 5, 1e9));
vector<vector<bool>> f(n + 5, vector<bool>(n + 5));
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (c[i][j] == 'M') sx = i, sy = j; else if (c[i][j] == 'H') d[i][j] = 1, q.emplace(i, j); else if (c[i][j] == 'D') tx = i, ty = j;
while (!q.empty()) {
auto [x, y] = q.front(); q.pop();
if (f[x][y]) continue; f[x][y] = 1;
for (int i = 0; i < 4; i++) {
int nx = x + cd[i][0], ny = y + cd[i][1];
if (nx <= 0 || nx > n || ny <= 0 || ny > n || c[nx][ny] == 'T') continue;
if (d[nx][ny] > d[x][y] + 1) d[nx][ny] = d[x][y] + 1, q.emplace(nx, ny);
}
}
auto bs = [&] (int val) {
vector<vector<int>> d2(n + 5, vector<int>(n + 5, 1e9));
vector<vector<bool>> f2(n + 5, vector<bool>(n + 5));
queue<tp> cq; d2[sx][sy] = val + 1; cq.emplace(sx, sy, 0);
while (!cq.empty()) {
auto [x, y, t] = cq.front(); cq.pop();
if (f2[x][y]) continue; f2[x][y] = 1;
int nt = t + 1, nts = (t + 1) % s;
for (int i = 0; i < 4; i++) {
int nx = x + cd[i][0], ny = y + cd[i][1];
if (nx <= 0 || nx > n || ny <= 0 || ny > n || c[nx][ny] == 'T') continue;
if (!nts) d2[nx][ny] = d2[x][y] + 1;
else d2[nx][ny] = d2[x][y];
if (d2[nx][ny] < d[nx][ny]) cq.emplace(nx, ny, nt);
}
}
return d2[tx][ty] != 1e9;
};
int l = 0, r = 1e5;
while (l <= r) {
int mid = (l + r) >> 1;
if (bs(mid)) l = mid + 1;
else r = mid - 1;
}
if (bs(0)) printf("%d", r);
else printf("-1");
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:20:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
20 | if (f[x][y]) continue; f[x][y] = 1;
| ^~
mecho.cpp:20:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
20 | if (f[x][y]) continue; f[x][y] = 1;
| ^
mecho.cpp: In lambda function:
mecho.cpp:33:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
33 | if (f2[x][y]) continue; f2[x][y] = 1;
| ^~
mecho.cpp:33:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
33 | if (f2[x][y]) continue; f2[x][y] = 1;
| ^~
mecho.cpp: In function 'int main()':
mecho.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d %d", &n, &s);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
117 ms |
6472 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 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 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
448 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
6 ms |
1664 KB |
Output is correct |
34 |
Correct |
7 ms |
1628 KB |
Output is correct |
35 |
Correct |
26 ms |
1628 KB |
Output is correct |
36 |
Correct |
7 ms |
2204 KB |
Output is correct |
37 |
Correct |
8 ms |
1884 KB |
Output is correct |
38 |
Correct |
37 ms |
2008 KB |
Output is correct |
39 |
Incorrect |
9 ms |
2392 KB |
Output isn't correct |
40 |
Correct |
11 ms |
2396 KB |
Output is correct |
41 |
Correct |
49 ms |
2408 KB |
Output is correct |
42 |
Incorrect |
15 ms |
2856 KB |
Output isn't correct |
43 |
Correct |
14 ms |
2652 KB |
Output is correct |
44 |
Correct |
63 ms |
2652 KB |
Output is correct |
45 |
Incorrect |
20 ms |
3164 KB |
Output isn't correct |
46 |
Correct |
15 ms |
3348 KB |
Output is correct |
47 |
Correct |
82 ms |
3352 KB |
Output is correct |
48 |
Incorrect |
27 ms |
3888 KB |
Output isn't correct |
49 |
Correct |
26 ms |
3764 KB |
Output is correct |
50 |
Correct |
88 ms |
3884 KB |
Output is correct |
51 |
Incorrect |
36 ms |
4324 KB |
Output isn't correct |
52 |
Incorrect |
24 ms |
4444 KB |
Output isn't correct |
53 |
Correct |
102 ms |
4468 KB |
Output is correct |
54 |
Incorrect |
41 ms |
4956 KB |
Output isn't correct |
55 |
Incorrect |
37 ms |
4956 KB |
Output isn't correct |
56 |
Correct |
120 ms |
5100 KB |
Output is correct |
57 |
Incorrect |
48 ms |
5724 KB |
Output isn't correct |
58 |
Incorrect |
50 ms |
5748 KB |
Output isn't correct |
59 |
Correct |
132 ms |
5720 KB |
Output is correct |
60 |
Incorrect |
59 ms |
6464 KB |
Output isn't correct |
61 |
Incorrect |
64 ms |
6264 KB |
Output isn't correct |
62 |
Correct |
167 ms |
6460 KB |
Output is correct |
63 |
Correct |
121 ms |
6448 KB |
Output is correct |
64 |
Correct |
185 ms |
6228 KB |
Output is correct |
65 |
Correct |
176 ms |
6452 KB |
Output is correct |
66 |
Correct |
151 ms |
6232 KB |
Output is correct |
67 |
Correct |
132 ms |
6224 KB |
Output is correct |
68 |
Correct |
55 ms |
6280 KB |
Output is correct |
69 |
Correct |
46 ms |
6224 KB |
Output is correct |
70 |
Correct |
45 ms |
6232 KB |
Output is correct |
71 |
Correct |
43 ms |
6224 KB |
Output is correct |
72 |
Incorrect |
44 ms |
6472 KB |
Output isn't correct |
73 |
Incorrect |
47 ms |
6480 KB |
Output isn't correct |
74 |
Correct |
95 ms |
6472 KB |
Output is correct |
75 |
Correct |
98 ms |
6472 KB |
Output is correct |
76 |
Correct |
76 ms |
6468 KB |
Output is correct |
77 |
Correct |
95 ms |
6476 KB |
Output is correct |
78 |
Correct |
109 ms |
6484 KB |
Output is correct |
79 |
Correct |
87 ms |
6480 KB |
Output is correct |
80 |
Correct |
78 ms |
6484 KB |
Output is correct |
81 |
Correct |
97 ms |
6492 KB |
Output is correct |
82 |
Correct |
81 ms |
6480 KB |
Output is correct |
83 |
Correct |
108 ms |
6476 KB |
Output is correct |
84 |
Correct |
118 ms |
6476 KB |
Output is correct |
85 |
Correct |
101 ms |
6236 KB |
Output is correct |
86 |
Correct |
96 ms |
6284 KB |
Output is correct |
87 |
Correct |
96 ms |
6492 KB |
Output is correct |
88 |
Correct |
122 ms |
6460 KB |
Output is correct |
89 |
Correct |
114 ms |
6472 KB |
Output is correct |
90 |
Correct |
106 ms |
6484 KB |
Output is correct |
91 |
Correct |
108 ms |
6480 KB |
Output is correct |
92 |
Correct |
110 ms |
6480 KB |
Output is correct |