# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759154 |
2023-06-15T19:55:50 Z |
bane |
Mecho (IOI09_mecho) |
C++17 |
|
155 ms |
6348 KB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
int n, s, times[802][802];
vector<string> v(802);
pair<int, int> st, en;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
inline bool valid(int x, int y) {
return (x >= 0 && x < n && y >= 0 && y < n && v[x][y] != 'T');
}
bool check(int m) {
if (m >= times[st.first][st.second]) return 0;
queue<pair<int, int>> q;
q.push(st);
int vis[n + 2][n + 2];
memset(vis, -1, sizeof(vis));
vis[st.first][st.second] = m;
while(!q.empty()){
int x = q.front().first, y = q.front().second;
q.pop();
int dist = vis[x][y];
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (valid(nx, ny) && dist + (dist + 1 == s) < times[nx][ny] && vis[nx][ny]==-1) {
vis[nx][ny] = dist + (dist + 1 == s);
q.push({nx, ny});
if (make_pair(nx, ny) == en) return 1;
}
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> s;
queue<pair<int, int>> h;
for (int i = 0; i < n; i++) {
cin >> v[i];
for (int j = 0; j < n; j++) {
times[i][j] = (int)1e9;
if (v[i][j] == 'M') st = {i, j};
if (v[i][j] == 'H') {
h.push({i, j});
times[i][j] = 0;
}
if (v[i][j] == 'D') en = {i, j};
}
}
while (h.size() > 0) {
int x = h.front().first, y = h.front().second;
h.pop();
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (valid(nx, ny) && times[x][y] + 1 < times[nx][ny]) {
times[nx][ny] = times[x][y] + 1;
h.push({nx, ny});
}
}
}
int l = -1, r = n * n;
while (l + 1 < r) {
int m = (l + r) / 2;
if (check(m)) l = m;
else r = m;
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
80 ms |
6156 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Incorrect |
1 ms |
488 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
33 |
Incorrect |
2 ms |
2004 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
2004 KB |
Output isn't correct |
35 |
Incorrect |
21 ms |
2068 KB |
Output isn't correct |
36 |
Incorrect |
3 ms |
2388 KB |
Output isn't correct |
37 |
Incorrect |
3 ms |
2388 KB |
Output isn't correct |
38 |
Incorrect |
22 ms |
2388 KB |
Output isn't correct |
39 |
Incorrect |
4 ms |
2772 KB |
Output isn't correct |
40 |
Incorrect |
3 ms |
2744 KB |
Output isn't correct |
41 |
Incorrect |
31 ms |
2772 KB |
Output isn't correct |
42 |
Incorrect |
4 ms |
3156 KB |
Output isn't correct |
43 |
Incorrect |
4 ms |
3156 KB |
Output isn't correct |
44 |
Incorrect |
38 ms |
3156 KB |
Output isn't correct |
45 |
Incorrect |
5 ms |
3544 KB |
Output isn't correct |
46 |
Incorrect |
5 ms |
3540 KB |
Output isn't correct |
47 |
Incorrect |
44 ms |
3568 KB |
Output isn't correct |
48 |
Incorrect |
6 ms |
3924 KB |
Output isn't correct |
49 |
Incorrect |
6 ms |
3924 KB |
Output isn't correct |
50 |
Incorrect |
51 ms |
3924 KB |
Output isn't correct |
51 |
Incorrect |
7 ms |
4480 KB |
Output isn't correct |
52 |
Incorrect |
9 ms |
4420 KB |
Output isn't correct |
53 |
Incorrect |
64 ms |
4436 KB |
Output isn't correct |
54 |
Incorrect |
8 ms |
4960 KB |
Output isn't correct |
55 |
Incorrect |
7 ms |
4948 KB |
Output isn't correct |
56 |
Incorrect |
73 ms |
4996 KB |
Output isn't correct |
57 |
Incorrect |
8 ms |
5460 KB |
Output isn't correct |
58 |
Incorrect |
9 ms |
5488 KB |
Output isn't correct |
59 |
Incorrect |
81 ms |
5460 KB |
Output isn't correct |
60 |
Incorrect |
10 ms |
5960 KB |
Output isn't correct |
61 |
Incorrect |
9 ms |
5972 KB |
Output isn't correct |
62 |
Incorrect |
118 ms |
6048 KB |
Output isn't correct |
63 |
Incorrect |
89 ms |
6036 KB |
Output isn't correct |
64 |
Correct |
155 ms |
6032 KB |
Output is correct |
65 |
Incorrect |
112 ms |
6028 KB |
Output isn't correct |
66 |
Incorrect |
96 ms |
5964 KB |
Output isn't correct |
67 |
Incorrect |
129 ms |
6032 KB |
Output isn't correct |
68 |
Incorrect |
37 ms |
6060 KB |
Output isn't correct |
69 |
Correct |
38 ms |
6052 KB |
Output is correct |
70 |
Incorrect |
37 ms |
6056 KB |
Output isn't correct |
71 |
Incorrect |
35 ms |
5972 KB |
Output isn't correct |
72 |
Correct |
22 ms |
5996 KB |
Output is correct |
73 |
Correct |
32 ms |
6252 KB |
Output is correct |
74 |
Incorrect |
74 ms |
6248 KB |
Output isn't correct |
75 |
Incorrect |
51 ms |
6252 KB |
Output isn't correct |
76 |
Incorrect |
46 ms |
6236 KB |
Output isn't correct |
77 |
Incorrect |
53 ms |
6288 KB |
Output isn't correct |
78 |
Incorrect |
62 ms |
6284 KB |
Output isn't correct |
79 |
Incorrect |
39 ms |
6228 KB |
Output isn't correct |
80 |
Incorrect |
36 ms |
6228 KB |
Output isn't correct |
81 |
Incorrect |
48 ms |
6224 KB |
Output isn't correct |
82 |
Incorrect |
47 ms |
6348 KB |
Output isn't correct |
83 |
Incorrect |
64 ms |
6228 KB |
Output isn't correct |
84 |
Incorrect |
56 ms |
6176 KB |
Output isn't correct |
85 |
Incorrect |
48 ms |
6236 KB |
Output isn't correct |
86 |
Incorrect |
61 ms |
6228 KB |
Output isn't correct |
87 |
Incorrect |
61 ms |
6244 KB |
Output isn't correct |
88 |
Incorrect |
106 ms |
6196 KB |
Output isn't correct |
89 |
Incorrect |
67 ms |
6128 KB |
Output isn't correct |
90 |
Incorrect |
69 ms |
6132 KB |
Output isn't correct |
91 |
Incorrect |
68 ms |
6100 KB |
Output isn't correct |
92 |
Incorrect |
69 ms |
6196 KB |
Output isn't correct |