# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759112 |
2023-06-15T18:56:43 Z |
Blagoj |
Mecho (IOI09_mecho) |
C++14 |
|
57 ms |
5052 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);
}
bool check(int m) {
if (m > times[en.first][en.second]) return 0;
int moves = 0;
queue<pair<int, int>> q;
q.push(st);
bool vis[n][n];
memset(vis, 0, sizeof(vis));
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;
if (make_pair(nx, ny) == en) return 1;
q.push({nx, ny});
}
else if (make_pair(nx, ny) == en) return 0;
}
}
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 = 0, r = n * n + 2;
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 |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
360 KB |
Output isn't correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
48 ms |
4820 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
356 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
10 |
Correct |
1 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 |
484 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
468 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 |
356 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
356 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 |
1 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 |
488 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
488 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 |
3 ms |
1748 KB |
Output isn't correct |
34 |
Incorrect |
7 ms |
1824 KB |
Output isn't correct |
35 |
Incorrect |
12 ms |
1704 KB |
Output isn't correct |
36 |
Incorrect |
4 ms |
2004 KB |
Output isn't correct |
37 |
Incorrect |
8 ms |
2028 KB |
Output isn't correct |
38 |
Incorrect |
13 ms |
2092 KB |
Output isn't correct |
39 |
Incorrect |
5 ms |
2288 KB |
Output isn't correct |
40 |
Incorrect |
8 ms |
2292 KB |
Output isn't correct |
41 |
Incorrect |
12 ms |
2384 KB |
Output isn't correct |
42 |
Incorrect |
6 ms |
2672 KB |
Output isn't correct |
43 |
Incorrect |
11 ms |
2644 KB |
Output isn't correct |
44 |
Incorrect |
27 ms |
2676 KB |
Output isn't correct |
45 |
Incorrect |
8 ms |
2948 KB |
Output isn't correct |
46 |
Incorrect |
17 ms |
2984 KB |
Output isn't correct |
47 |
Incorrect |
24 ms |
2932 KB |
Output isn't correct |
48 |
Incorrect |
8 ms |
3284 KB |
Output isn't correct |
49 |
Incorrect |
19 ms |
3284 KB |
Output isn't correct |
50 |
Incorrect |
27 ms |
3284 KB |
Output isn't correct |
51 |
Incorrect |
9 ms |
3668 KB |
Output isn't correct |
52 |
Incorrect |
24 ms |
3660 KB |
Output isn't correct |
53 |
Incorrect |
24 ms |
3652 KB |
Output isn't correct |
54 |
Incorrect |
10 ms |
4024 KB |
Output isn't correct |
55 |
Incorrect |
27 ms |
3948 KB |
Output isn't correct |
56 |
Incorrect |
45 ms |
3944 KB |
Output isn't correct |
57 |
Incorrect |
12 ms |
4340 KB |
Output isn't correct |
58 |
Incorrect |
33 ms |
4400 KB |
Output isn't correct |
59 |
Incorrect |
57 ms |
4308 KB |
Output isn't correct |
60 |
Incorrect |
13 ms |
4692 KB |
Output isn't correct |
61 |
Incorrect |
34 ms |
4720 KB |
Output isn't correct |
62 |
Incorrect |
47 ms |
4780 KB |
Output isn't correct |
63 |
Incorrect |
14 ms |
4692 KB |
Output isn't correct |
64 |
Incorrect |
13 ms |
4712 KB |
Output isn't correct |
65 |
Incorrect |
13 ms |
4692 KB |
Output isn't correct |
66 |
Incorrect |
13 ms |
4692 KB |
Output isn't correct |
67 |
Incorrect |
13 ms |
4688 KB |
Output isn't correct |
68 |
Incorrect |
16 ms |
4948 KB |
Output isn't correct |
69 |
Incorrect |
18 ms |
4972 KB |
Output isn't correct |
70 |
Incorrect |
15 ms |
4828 KB |
Output isn't correct |
71 |
Incorrect |
16 ms |
4820 KB |
Output isn't correct |
72 |
Incorrect |
16 ms |
4840 KB |
Output isn't correct |
73 |
Incorrect |
20 ms |
4956 KB |
Output isn't correct |
74 |
Incorrect |
29 ms |
4980 KB |
Output isn't correct |
75 |
Incorrect |
45 ms |
5048 KB |
Output isn't correct |
76 |
Incorrect |
40 ms |
5052 KB |
Output isn't correct |
77 |
Incorrect |
36 ms |
5028 KB |
Output isn't correct |
78 |
Incorrect |
46 ms |
5024 KB |
Output isn't correct |
79 |
Incorrect |
24 ms |
5032 KB |
Output isn't correct |
80 |
Incorrect |
37 ms |
4948 KB |
Output isn't correct |
81 |
Incorrect |
45 ms |
5024 KB |
Output isn't correct |
82 |
Incorrect |
38 ms |
4948 KB |
Output isn't correct |
83 |
Incorrect |
47 ms |
4944 KB |
Output isn't correct |
84 |
Incorrect |
43 ms |
4984 KB |
Output isn't correct |
85 |
Incorrect |
51 ms |
4980 KB |
Output isn't correct |
86 |
Incorrect |
47 ms |
4892 KB |
Output isn't correct |
87 |
Incorrect |
47 ms |
4940 KB |
Output isn't correct |
88 |
Incorrect |
45 ms |
4928 KB |
Output isn't correct |
89 |
Incorrect |
40 ms |
4900 KB |
Output isn't correct |
90 |
Incorrect |
48 ms |
4824 KB |
Output isn't correct |
91 |
Incorrect |
48 ms |
4820 KB |
Output isn't correct |
92 |
Incorrect |
52 ms |
4896 KB |
Output isn't correct |