# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759133 |
2023-06-15T19:23:42 Z |
Blagoj |
Mecho (IOI09_mecho) |
C++17 |
|
167 ms |
4448 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);
bool vis[n + 2][n + 2];
memset(vis, 0, sizeof(vis));
vis[st.first][st.second] = 1;
int moves = 0;
do {
int sz = q.size();
while (sz--) {
int x = q.front().first, y = q.front().second;
q.pop();
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (valid(nx, ny) && m < times[nx][ny] && !vis[nx][ny]) {
vis[nx][ny] = 1;
q.push({nx, ny});
if (make_pair(nx, ny) == en) return 1;
}
}
}
moves++;
if (moves >= s) {
moves = 0;
m++;
}
}
while (q.size() > 0);
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] = n * n + 1000;
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 + 100;
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 |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
74 ms |
4180 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
26 |
Correct |
0 ms |
468 KB |
Output is correct |
27 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Incorrect |
2 ms |
1620 KB |
Output isn't correct |
34 |
Correct |
3 ms |
1700 KB |
Output is correct |
35 |
Correct |
16 ms |
1700 KB |
Output is correct |
36 |
Incorrect |
4 ms |
1876 KB |
Output isn't correct |
37 |
Correct |
3 ms |
1876 KB |
Output is correct |
38 |
Correct |
19 ms |
1932 KB |
Output is correct |
39 |
Incorrect |
5 ms |
2112 KB |
Output isn't correct |
40 |
Correct |
3 ms |
2132 KB |
Output is correct |
41 |
Correct |
26 ms |
2184 KB |
Output is correct |
42 |
Incorrect |
4 ms |
2396 KB |
Output isn't correct |
43 |
Correct |
6 ms |
2388 KB |
Output is correct |
44 |
Correct |
42 ms |
2412 KB |
Output is correct |
45 |
Incorrect |
4 ms |
2644 KB |
Output isn't correct |
46 |
Correct |
6 ms |
2652 KB |
Output is correct |
47 |
Correct |
48 ms |
2680 KB |
Output is correct |
48 |
Incorrect |
5 ms |
2876 KB |
Output isn't correct |
49 |
Correct |
5 ms |
2900 KB |
Output is correct |
50 |
Correct |
50 ms |
2964 KB |
Output is correct |
51 |
Incorrect |
6 ms |
3156 KB |
Output isn't correct |
52 |
Correct |
6 ms |
3156 KB |
Output is correct |
53 |
Correct |
55 ms |
3156 KB |
Output is correct |
54 |
Incorrect |
7 ms |
3492 KB |
Output isn't correct |
55 |
Correct |
7 ms |
3544 KB |
Output is correct |
56 |
Correct |
67 ms |
3464 KB |
Output is correct |
57 |
Incorrect |
8 ms |
3796 KB |
Output isn't correct |
58 |
Correct |
11 ms |
3796 KB |
Output is correct |
59 |
Correct |
82 ms |
3840 KB |
Output is correct |
60 |
Incorrect |
8 ms |
4052 KB |
Output isn't correct |
61 |
Correct |
8 ms |
4100 KB |
Output is correct |
62 |
Correct |
115 ms |
4148 KB |
Output is correct |
63 |
Correct |
78 ms |
4144 KB |
Output is correct |
64 |
Correct |
167 ms |
4144 KB |
Output is correct |
65 |
Correct |
123 ms |
4140 KB |
Output is correct |
66 |
Incorrect |
98 ms |
4044 KB |
Output isn't correct |
67 |
Correct |
93 ms |
4148 KB |
Output is correct |
68 |
Correct |
38 ms |
4172 KB |
Output is correct |
69 |
Correct |
34 ms |
4168 KB |
Output is correct |
70 |
Correct |
27 ms |
4044 KB |
Output is correct |
71 |
Correct |
27 ms |
4188 KB |
Output is correct |
72 |
Incorrect |
24 ms |
4156 KB |
Output isn't correct |
73 |
Incorrect |
29 ms |
4420 KB |
Output isn't correct |
74 |
Correct |
44 ms |
4448 KB |
Output is correct |
75 |
Correct |
53 ms |
4420 KB |
Output is correct |
76 |
Correct |
63 ms |
4436 KB |
Output is correct |
77 |
Correct |
59 ms |
4424 KB |
Output is correct |
78 |
Correct |
66 ms |
4392 KB |
Output is correct |
79 |
Correct |
32 ms |
4404 KB |
Output is correct |
80 |
Correct |
43 ms |
4400 KB |
Output is correct |
81 |
Correct |
68 ms |
4388 KB |
Output is correct |
82 |
Correct |
52 ms |
4308 KB |
Output is correct |
83 |
Correct |
78 ms |
4352 KB |
Output is correct |
84 |
Correct |
51 ms |
4356 KB |
Output is correct |
85 |
Correct |
73 ms |
4264 KB |
Output is correct |
86 |
Correct |
63 ms |
4252 KB |
Output is correct |
87 |
Correct |
55 ms |
4356 KB |
Output is correct |
88 |
Correct |
59 ms |
4308 KB |
Output is correct |
89 |
Correct |
71 ms |
4304 KB |
Output is correct |
90 |
Correct |
63 ms |
4296 KB |
Output is correct |
91 |
Correct |
67 ms |
4308 KB |
Output is correct |
92 |
Correct |
75 ms |
4304 KB |
Output is correct |