# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101365 |
2024-10-16T07:20:31 Z |
jadai007 |
Mecho (IOI09_mecho) |
C++17 |
|
470 ms |
18528 KB |
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, s, disH[1010][1010], dis[1010][1010], xx[] = {0, 0, -1, 1}, xy[] = {-1, 1, 0, 0};
char mp[1010][1010];
queue<tuple<int, int, int>> q;
bool solve(int mid){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(mp[i][j] == 'M') q.emplace(i, j, mid*s), dis[i][j] = mid*s;
else dis[i][j] = 1e18;
}
}
while(!q.empty()){
int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop();
if(dis[x][y] < w || dis[x][y] >= disH[x][y]) continue;
if(mp[x][y] == 'D') return true;
for(int i = 0; i < 4; ++i){
int nx = x + xx[i];
int ny = y + xy[i];
if(nx < 1 || nx > n || ny < 1 || ny > n || mp[nx][ny] == 'T') continue;
if(dis[nx][ny] > w + 1){
dis[nx][ny] = w + 1;
q.emplace(nx, ny, w + 1);
}
}
}
return false;
}
int32_t main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> s;
for(int i = 1; i<=n; ++i) for(int j = 1; j <= n; ++j) cin >> mp[i][j];
for(int i = 1; i <= n; ++i){
for(int j = 1; j <=n; ++j){
if(mp[i][j] == 'H') q.emplace(i, j, 0), disH[i][j] = 0;
else disH[i][j] = 1e18;
}
}
while(!q.empty()){
int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop();
if(disH[x][y] < w) continue;
for(int i = 0; i < 4; ++i){
int nx = x + xx[i];
int ny = y + xy[i];
if(nx < 1 || nx > n || ny < 1 || ny > n || mp[nx][ny] == 'T') continue;
if(disH[nx][ny] > w + 1){
disH[nx][ny] = w + 1;
q.emplace(nx, ny, w + 1);
}
}
}
for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) disH[i][j] == 1e18 ? disH[i][j] *= 1 : disH[i][j] *= s;
int l = 0, r = 1e18, ans = -1;
//for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) cout << i << ' ' << j << ' ' << disH[i][j] << '\n';
while(l <= r){
int mid = (l + r) >> 1;
if(solve(mid)) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4692 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4436 KB |
Output isn't correct |
3 |
Correct |
1 ms |
4436 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4436 KB |
Output isn't correct |
5 |
Correct |
1 ms |
4436 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4436 KB |
Output isn't correct |
7 |
Incorrect |
302 ms |
18004 KB |
Output isn't correct |
8 |
Correct |
1 ms |
4436 KB |
Output is correct |
9 |
Correct |
1 ms |
4436 KB |
Output is correct |
10 |
Correct |
1 ms |
4564 KB |
Output is correct |
11 |
Correct |
2 ms |
4692 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4436 KB |
Output isn't correct |
13 |
Correct |
1 ms |
4436 KB |
Output is correct |
14 |
Correct |
1 ms |
4436 KB |
Output is correct |
15 |
Correct |
1 ms |
4436 KB |
Output is correct |
16 |
Correct |
1 ms |
4436 KB |
Output is correct |
17 |
Correct |
1 ms |
4436 KB |
Output is correct |
18 |
Correct |
1 ms |
4436 KB |
Output is correct |
19 |
Correct |
1 ms |
4596 KB |
Output is correct |
20 |
Correct |
1 ms |
4436 KB |
Output is correct |
21 |
Correct |
1 ms |
4608 KB |
Output is correct |
22 |
Incorrect |
1 ms |
4436 KB |
Output isn't correct |
23 |
Correct |
1 ms |
4560 KB |
Output is correct |
24 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
25 |
Correct |
1 ms |
4436 KB |
Output is correct |
26 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
27 |
Correct |
2 ms |
4604 KB |
Output is correct |
28 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
29 |
Correct |
1 ms |
4436 KB |
Output is correct |
30 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
31 |
Correct |
2 ms |
4572 KB |
Output is correct |
32 |
Incorrect |
2 ms |
4436 KB |
Output isn't correct |
33 |
Correct |
9 ms |
8788 KB |
Output is correct |
34 |
Incorrect |
9 ms |
8968 KB |
Output isn't correct |
35 |
Incorrect |
34 ms |
8800 KB |
Output isn't correct |
36 |
Correct |
11 ms |
8788 KB |
Output is correct |
37 |
Incorrect |
12 ms |
8788 KB |
Output isn't correct |
38 |
Incorrect |
46 ms |
8788 KB |
Output isn't correct |
39 |
Correct |
14 ms |
13140 KB |
Output is correct |
40 |
Incorrect |
15 ms |
13156 KB |
Output isn't correct |
41 |
Incorrect |
65 ms |
13140 KB |
Output isn't correct |
42 |
Correct |
17 ms |
13140 KB |
Output is correct |
43 |
Incorrect |
17 ms |
13136 KB |
Output isn't correct |
44 |
Incorrect |
85 ms |
13140 KB |
Output isn't correct |
45 |
Correct |
19 ms |
13140 KB |
Output is correct |
46 |
Incorrect |
20 ms |
13140 KB |
Output isn't correct |
47 |
Incorrect |
120 ms |
13268 KB |
Output isn't correct |
48 |
Correct |
26 ms |
13140 KB |
Output is correct |
49 |
Incorrect |
23 ms |
13152 KB |
Output isn't correct |
50 |
Incorrect |
106 ms |
13324 KB |
Output isn't correct |
51 |
Correct |
27 ms |
13140 KB |
Output is correct |
52 |
Incorrect |
27 ms |
13140 KB |
Output isn't correct |
53 |
Incorrect |
132 ms |
13380 KB |
Output isn't correct |
54 |
Correct |
32 ms |
15444 KB |
Output is correct |
55 |
Incorrect |
31 ms |
15440 KB |
Output isn't correct |
56 |
Incorrect |
160 ms |
15444 KB |
Output isn't correct |
57 |
Correct |
40 ms |
17492 KB |
Output is correct |
58 |
Incorrect |
36 ms |
17492 KB |
Output isn't correct |
59 |
Incorrect |
181 ms |
17492 KB |
Output isn't correct |
60 |
Correct |
39 ms |
17492 KB |
Output is correct |
61 |
Incorrect |
41 ms |
17492 KB |
Output isn't correct |
62 |
Incorrect |
203 ms |
17656 KB |
Output isn't correct |
63 |
Correct |
102 ms |
17484 KB |
Output is correct |
64 |
Incorrect |
470 ms |
17688 KB |
Output isn't correct |
65 |
Correct |
135 ms |
17492 KB |
Output is correct |
66 |
Correct |
115 ms |
17492 KB |
Output is correct |
67 |
Correct |
106 ms |
17492 KB |
Output is correct |
68 |
Incorrect |
425 ms |
17772 KB |
Output isn't correct |
69 |
Incorrect |
316 ms |
17752 KB |
Output isn't correct |
70 |
Incorrect |
403 ms |
17748 KB |
Output isn't correct |
71 |
Correct |
63 ms |
17748 KB |
Output is correct |
72 |
Incorrect |
62 ms |
17744 KB |
Output isn't correct |
73 |
Correct |
54 ms |
18516 KB |
Output is correct |
74 |
Incorrect |
247 ms |
18516 KB |
Output isn't correct |
75 |
Correct |
79 ms |
18248 KB |
Output is correct |
76 |
Correct |
68 ms |
18260 KB |
Output is correct |
77 |
Incorrect |
257 ms |
18516 KB |
Output isn't correct |
78 |
Correct |
74 ms |
18260 KB |
Output is correct |
79 |
Incorrect |
257 ms |
18528 KB |
Output isn't correct |
80 |
Correct |
74 ms |
18260 KB |
Output is correct |
81 |
Correct |
79 ms |
18412 KB |
Output is correct |
82 |
Incorrect |
231 ms |
18524 KB |
Output isn't correct |
83 |
Correct |
83 ms |
18144 KB |
Output is correct |
84 |
Incorrect |
251 ms |
18372 KB |
Output isn't correct |
85 |
Incorrect |
259 ms |
18260 KB |
Output isn't correct |
86 |
Correct |
80 ms |
18256 KB |
Output is correct |
87 |
Incorrect |
252 ms |
18144 KB |
Output isn't correct |
88 |
Incorrect |
309 ms |
18128 KB |
Output isn't correct |
89 |
Incorrect |
285 ms |
18156 KB |
Output isn't correct |
90 |
Incorrect |
274 ms |
18168 KB |
Output isn't correct |
91 |
Incorrect |
287 ms |
18004 KB |
Output isn't correct |
92 |
Incorrect |
285 ms |
18004 KB |
Output isn't correct |