# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
950872 |
2024-03-20T21:01:08 Z |
blackslex |
Mecho (IOI09_mecho) |
C++17 |
|
189 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' || c[nx][ny] == 'D') 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 = 1e6;
while (l <= r) {
int mid = (l + r) >> 1;
if (bs(mid)) l = mid + 1;
else r = mid - 1;
}
printf("%d", r);
}
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 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
101 ms |
6448 KB |
Output isn't correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
444 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
392 KB |
Output isn't correct |
33 |
Incorrect |
12 ms |
1624 KB |
Output isn't correct |
34 |
Incorrect |
22 ms |
1624 KB |
Output isn't correct |
35 |
Incorrect |
21 ms |
1628 KB |
Output isn't correct |
36 |
Incorrect |
16 ms |
1884 KB |
Output isn't correct |
37 |
Incorrect |
24 ms |
1992 KB |
Output isn't correct |
38 |
Incorrect |
27 ms |
2012 KB |
Output isn't correct |
39 |
Incorrect |
19 ms |
2396 KB |
Output isn't correct |
40 |
Incorrect |
31 ms |
2392 KB |
Output isn't correct |
41 |
Incorrect |
34 ms |
2396 KB |
Output isn't correct |
42 |
Incorrect |
28 ms |
2848 KB |
Output isn't correct |
43 |
Incorrect |
37 ms |
2648 KB |
Output isn't correct |
44 |
Incorrect |
45 ms |
2652 KB |
Output isn't correct |
45 |
Incorrect |
29 ms |
3344 KB |
Output isn't correct |
46 |
Incorrect |
46 ms |
3164 KB |
Output isn't correct |
47 |
Incorrect |
61 ms |
3340 KB |
Output isn't correct |
48 |
Incorrect |
35 ms |
3672 KB |
Output isn't correct |
49 |
Incorrect |
54 ms |
3676 KB |
Output isn't correct |
50 |
Incorrect |
66 ms |
3676 KB |
Output isn't correct |
51 |
Incorrect |
41 ms |
4448 KB |
Output isn't correct |
52 |
Incorrect |
67 ms |
4468 KB |
Output isn't correct |
53 |
Incorrect |
77 ms |
4440 KB |
Output isn't correct |
54 |
Incorrect |
47 ms |
4956 KB |
Output isn't correct |
55 |
Incorrect |
75 ms |
5076 KB |
Output isn't correct |
56 |
Incorrect |
98 ms |
5092 KB |
Output isn't correct |
57 |
Incorrect |
55 ms |
5720 KB |
Output isn't correct |
58 |
Incorrect |
87 ms |
5724 KB |
Output isn't correct |
59 |
Incorrect |
112 ms |
5768 KB |
Output isn't correct |
60 |
Incorrect |
62 ms |
6444 KB |
Output isn't correct |
61 |
Incorrect |
100 ms |
6448 KB |
Output isn't correct |
62 |
Incorrect |
130 ms |
6484 KB |
Output isn't correct |
63 |
Incorrect |
101 ms |
6452 KB |
Output isn't correct |
64 |
Incorrect |
189 ms |
6228 KB |
Output isn't correct |
65 |
Incorrect |
178 ms |
6228 KB |
Output isn't correct |
66 |
Incorrect |
139 ms |
6236 KB |
Output isn't correct |
67 |
Correct |
108 ms |
6236 KB |
Output is correct |
68 |
Incorrect |
45 ms |
6452 KB |
Output isn't correct |
69 |
Incorrect |
55 ms |
6236 KB |
Output isn't correct |
70 |
Incorrect |
41 ms |
6232 KB |
Output isn't correct |
71 |
Incorrect |
41 ms |
6236 KB |
Output isn't correct |
72 |
Incorrect |
64 ms |
6448 KB |
Output isn't correct |
73 |
Incorrect |
44 ms |
6480 KB |
Output isn't correct |
74 |
Incorrect |
122 ms |
6492 KB |
Output isn't correct |
75 |
Incorrect |
97 ms |
6480 KB |
Output isn't correct |
76 |
Incorrect |
72 ms |
6484 KB |
Output isn't correct |
77 |
Incorrect |
88 ms |
6484 KB |
Output isn't correct |
78 |
Correct |
82 ms |
6480 KB |
Output is correct |
79 |
Incorrect |
114 ms |
6336 KB |
Output isn't correct |
80 |
Incorrect |
92 ms |
6492 KB |
Output isn't correct |
81 |
Incorrect |
78 ms |
6480 KB |
Output isn't correct |
82 |
Incorrect |
85 ms |
6228 KB |
Output isn't correct |
83 |
Incorrect |
83 ms |
6348 KB |
Output isn't correct |
84 |
Incorrect |
116 ms |
6300 KB |
Output isn't correct |
85 |
Incorrect |
78 ms |
6480 KB |
Output isn't correct |
86 |
Incorrect |
100 ms |
6476 KB |
Output isn't correct |
87 |
Incorrect |
89 ms |
6480 KB |
Output isn't correct |
88 |
Incorrect |
85 ms |
6472 KB |
Output isn't correct |
89 |
Incorrect |
117 ms |
6488 KB |
Output isn't correct |
90 |
Incorrect |
93 ms |
6480 KB |
Output isn't correct |
91 |
Incorrect |
101 ms |
6460 KB |
Output isn't correct |
92 |
Incorrect |
91 ms |
6476 KB |
Output isn't correct |