# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
995506 |
2024-06-09T08:15:21 Z |
phoenix |
Mecho (IOI09_mecho) |
C++17 |
|
145 ms |
14432 KB |
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e8;
vector<pair<int, int>> dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, +1}};
int n, s;
char c[1000][1000];
int f[1000][1000];
pair<int, int> st, fi;
bool inside(pair<int, int> g) {
return (min(g.first, g.second) >= 0 && max(g.first, g.second) < n);
}
int t[1000][1000], step[1000][1000];
bool vis[1000][1000];
bool check(int T) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
step[i][j] = 0;
t[i][j] = INF;
vis[i][j] = false;
}
}
t[st.first][st.second] = T;
vis[st.first][st.second] = 1;
queue<pair<int, int>> q;
q.push(st);
while(!q.empty()) {
auto [x, y] = q.front();
q.pop();
if(c[x][y] == 'D') return 1;
if(t[x][y] > f[x][y] || (!step[x][y] && t[x][y] == f[x][y]))
continue;
for(auto [dx, dy] : dirs) {
pair<int, int> to = {x + dx, y + dy};
if(!inside(to) || vis[to.first][to.second]) continue;
vis[to.first][to.second] = true;
t[to.first][to.second] = t[x][y] + (step[x][y] == 0);
step[to.first][to.second] = (step[x][y] + 1) % s;
q.push(to);
}
}
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> s;
queue<pair<int, int>> h;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> c[i][j];
if(c[i][j] == 'H') {
h.push({i, j});
vis[i][j] = true;
}
if(c[i][j] == 'M')
st = {i, j};
if(c[i][j] == 'D') {
fi = {i, j};
vis[i][j] = true;
}
if(c[i][j] == 'T')
vis[i][j] = true;
}
}
while(!h.empty()) {
auto [x, y] = h.front();
h.pop();
for(auto [dx, dy] : dirs) {
pair<int, int> to = {x + dx, y + dy};
if(inside(to) && !vis[to.first][to.second]) {
vis[to.first][to.second] = true;
f[to.first][to.second] = f[x][y] + 1;
h.push(to);
}
}
}
int l = -1, r = 1e9;
while(r - l > 1) {
int m = (l + r) / 2;
if(check(m)) l = m;
else r = m;
}
cout << l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
60 ms |
13880 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6608 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6680 KB |
Output is correct |
23 |
Correct |
1 ms |
6488 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
1 ms |
6748 KB |
Output is correct |
29 |
Correct |
1 ms |
6744 KB |
Output is correct |
30 |
Correct |
1 ms |
6748 KB |
Output is correct |
31 |
Correct |
1 ms |
6748 KB |
Output is correct |
32 |
Correct |
1 ms |
6748 KB |
Output is correct |
33 |
Correct |
5 ms |
9180 KB |
Output is correct |
34 |
Correct |
8 ms |
9048 KB |
Output is correct |
35 |
Correct |
16 ms |
9052 KB |
Output is correct |
36 |
Correct |
6 ms |
11356 KB |
Output is correct |
37 |
Correct |
6 ms |
11364 KB |
Output is correct |
38 |
Correct |
20 ms |
11356 KB |
Output is correct |
39 |
Correct |
8 ms |
11356 KB |
Output is correct |
40 |
Correct |
8 ms |
13404 KB |
Output is correct |
41 |
Correct |
24 ms |
11612 KB |
Output is correct |
42 |
Correct |
10 ms |
11636 KB |
Output is correct |
43 |
Correct |
9 ms |
13404 KB |
Output is correct |
44 |
Correct |
34 ms |
11888 KB |
Output is correct |
45 |
Correct |
12 ms |
12144 KB |
Output is correct |
46 |
Correct |
11 ms |
13660 KB |
Output is correct |
47 |
Correct |
39 ms |
12124 KB |
Output is correct |
48 |
Correct |
13 ms |
12380 KB |
Output is correct |
49 |
Correct |
14 ms |
13656 KB |
Output is correct |
50 |
Correct |
49 ms |
12380 KB |
Output is correct |
51 |
Correct |
15 ms |
12752 KB |
Output is correct |
52 |
Correct |
15 ms |
13664 KB |
Output is correct |
53 |
Correct |
58 ms |
12636 KB |
Output is correct |
54 |
Correct |
18 ms |
12888 KB |
Output is correct |
55 |
Correct |
18 ms |
13916 KB |
Output is correct |
56 |
Correct |
64 ms |
12892 KB |
Output is correct |
57 |
Correct |
19 ms |
13136 KB |
Output is correct |
58 |
Correct |
19 ms |
14028 KB |
Output is correct |
59 |
Correct |
77 ms |
13148 KB |
Output is correct |
60 |
Correct |
26 ms |
13404 KB |
Output is correct |
61 |
Correct |
26 ms |
14164 KB |
Output is correct |
62 |
Correct |
83 ms |
13396 KB |
Output is correct |
63 |
Correct |
93 ms |
13396 KB |
Output is correct |
64 |
Correct |
139 ms |
13916 KB |
Output is correct |
65 |
Correct |
145 ms |
14168 KB |
Output is correct |
66 |
Correct |
99 ms |
13400 KB |
Output is correct |
67 |
Correct |
101 ms |
14136 KB |
Output is correct |
68 |
Correct |
45 ms |
13392 KB |
Output is correct |
69 |
Correct |
44 ms |
13572 KB |
Output is correct |
70 |
Correct |
32 ms |
13404 KB |
Output is correct |
71 |
Correct |
36 ms |
13400 KB |
Output is correct |
72 |
Correct |
33 ms |
13400 KB |
Output is correct |
73 |
Correct |
34 ms |
14216 KB |
Output is correct |
74 |
Correct |
44 ms |
14160 KB |
Output is correct |
75 |
Correct |
46 ms |
14380 KB |
Output is correct |
76 |
Correct |
49 ms |
14400 KB |
Output is correct |
77 |
Correct |
44 ms |
14432 KB |
Output is correct |
78 |
Correct |
49 ms |
13656 KB |
Output is correct |
79 |
Correct |
42 ms |
13920 KB |
Output is correct |
80 |
Correct |
44 ms |
13624 KB |
Output is correct |
81 |
Correct |
50 ms |
13788 KB |
Output is correct |
82 |
Correct |
43 ms |
13804 KB |
Output is correct |
83 |
Correct |
75 ms |
14172 KB |
Output is correct |
84 |
Correct |
50 ms |
13988 KB |
Output is correct |
85 |
Correct |
51 ms |
14168 KB |
Output is correct |
86 |
Correct |
53 ms |
14160 KB |
Output is correct |
87 |
Correct |
60 ms |
14368 KB |
Output is correct |
88 |
Correct |
55 ms |
14160 KB |
Output is correct |
89 |
Correct |
57 ms |
14172 KB |
Output is correct |
90 |
Correct |
61 ms |
14308 KB |
Output is correct |
91 |
Correct |
56 ms |
14164 KB |
Output is correct |
92 |
Correct |
62 ms |
14324 KB |
Output is correct |