# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
759158 |
2023-06-15T19:58:53 Z |
bane |
Mecho (IOI09_mecho) |
C++17 |
|
155 ms |
6332 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 = 0, r = n * n, ans = -1;
while(l<=r){
int mid = (l + r) >> 1;
if (check(mid)){
ans = mid;
l = mid + 1;
}else r = mid - 1;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
0 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 |
79 ms |
6100 KB |
Output isn't correct |
8 |
Incorrect |
0 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 |
468 KB |
Output is correct |
14 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
20 |
Incorrect |
0 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 |
512 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 |
620 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 |
15 ms |
2004 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 |
2408 KB |
Output isn't correct |
39 |
Incorrect |
4 ms |
2772 KB |
Output isn't correct |
40 |
Incorrect |
4 ms |
2772 KB |
Output isn't correct |
41 |
Incorrect |
30 ms |
2772 KB |
Output isn't correct |
42 |
Incorrect |
4 ms |
3156 KB |
Output isn't correct |
43 |
Incorrect |
4 ms |
3084 KB |
Output isn't correct |
44 |
Incorrect |
38 ms |
3156 KB |
Output isn't correct |
45 |
Incorrect |
5 ms |
3540 KB |
Output isn't correct |
46 |
Incorrect |
8 ms |
3668 KB |
Output isn't correct |
47 |
Incorrect |
45 ms |
3540 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 |
54 ms |
3924 KB |
Output isn't correct |
51 |
Incorrect |
7 ms |
4380 KB |
Output isn't correct |
52 |
Incorrect |
7 ms |
4384 KB |
Output isn't correct |
53 |
Incorrect |
77 ms |
4488 KB |
Output isn't correct |
54 |
Incorrect |
9 ms |
4888 KB |
Output isn't correct |
55 |
Incorrect |
7 ms |
4948 KB |
Output isn't correct |
56 |
Incorrect |
75 ms |
4992 KB |
Output isn't correct |
57 |
Incorrect |
9 ms |
5460 KB |
Output isn't correct |
58 |
Incorrect |
9 ms |
5460 KB |
Output isn't correct |
59 |
Incorrect |
89 ms |
5500 KB |
Output isn't correct |
60 |
Incorrect |
10 ms |
5972 KB |
Output isn't correct |
61 |
Incorrect |
9 ms |
5972 KB |
Output isn't correct |
62 |
Incorrect |
145 ms |
5968 KB |
Output isn't correct |
63 |
Incorrect |
98 ms |
6032 KB |
Output isn't correct |
64 |
Correct |
155 ms |
6024 KB |
Output is correct |
65 |
Incorrect |
113 ms |
6036 KB |
Output isn't correct |
66 |
Incorrect |
81 ms |
5972 KB |
Output isn't correct |
67 |
Incorrect |
114 ms |
5972 KB |
Output isn't correct |
68 |
Incorrect |
33 ms |
5996 KB |
Output isn't correct |
69 |
Correct |
33 ms |
5972 KB |
Output is correct |
70 |
Incorrect |
36 ms |
6100 KB |
Output isn't correct |
71 |
Incorrect |
37 ms |
5988 KB |
Output isn't correct |
72 |
Correct |
24 ms |
5996 KB |
Output is correct |
73 |
Correct |
33 ms |
6224 KB |
Output is correct |
74 |
Incorrect |
54 ms |
6312 KB |
Output isn't correct |
75 |
Incorrect |
60 ms |
6252 KB |
Output isn't correct |
76 |
Incorrect |
53 ms |
6312 KB |
Output isn't correct |
77 |
Incorrect |
62 ms |
6316 KB |
Output isn't correct |
78 |
Incorrect |
78 ms |
6276 KB |
Output isn't correct |
79 |
Incorrect |
43 ms |
6224 KB |
Output isn't correct |
80 |
Incorrect |
49 ms |
6332 KB |
Output isn't correct |
81 |
Incorrect |
61 ms |
6280 KB |
Output isn't correct |
82 |
Incorrect |
44 ms |
6284 KB |
Output isn't correct |
83 |
Incorrect |
83 ms |
6176 KB |
Output isn't correct |
84 |
Incorrect |
67 ms |
6264 KB |
Output isn't correct |
85 |
Incorrect |
52 ms |
6244 KB |
Output isn't correct |
86 |
Incorrect |
66 ms |
6248 KB |
Output isn't correct |
87 |
Incorrect |
80 ms |
6228 KB |
Output isn't correct |
88 |
Incorrect |
96 ms |
6200 KB |
Output isn't correct |
89 |
Incorrect |
91 ms |
6208 KB |
Output isn't correct |
90 |
Incorrect |
73 ms |
6108 KB |
Output isn't correct |
91 |
Incorrect |
72 ms |
6184 KB |
Output isn't correct |
92 |
Incorrect |
67 ms |
6100 KB |
Output isn't correct |