# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101369 |
2024-10-16T07:25:00 Z |
jadai007 |
Mecho (IOI09_mecho) |
C++17 |
|
245 ms |
9288 KB |
#include<bits/stdc++.h>
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] = 1e9;
}
}
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;
}
int 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] = 1e9;
}
}
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] == 1e9 ? disH[i][j] *= 1 : disH[i][j] *= s;
int l = 0, r = 1e9, 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 |
4432 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
3 |
Correct |
1 ms |
4432 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
7 |
Incorrect |
155 ms |
9012 KB |
Output isn't correct |
8 |
Correct |
1 ms |
4432 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
10 |
Correct |
2 ms |
4604 KB |
Output is correct |
11 |
Correct |
1 ms |
4432 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4604 KB |
Output isn't correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
15 |
Correct |
1 ms |
4432 KB |
Output is correct |
16 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
19 |
Correct |
1 ms |
4432 KB |
Output is correct |
20 |
Incorrect |
2 ms |
4496 KB |
Output isn't correct |
21 |
Correct |
1 ms |
4432 KB |
Output is correct |
22 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
23 |
Correct |
2 ms |
4432 KB |
Output is correct |
24 |
Incorrect |
1 ms |
4624 KB |
Output isn't correct |
25 |
Correct |
1 ms |
4432 KB |
Output is correct |
26 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
27 |
Correct |
1 ms |
4432 KB |
Output is correct |
28 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
29 |
Correct |
1 ms |
4432 KB |
Output is correct |
30 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
31 |
Correct |
1 ms |
4432 KB |
Output is correct |
32 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
33 |
Correct |
6 ms |
8784 KB |
Output is correct |
34 |
Incorrect |
7 ms |
8784 KB |
Output isn't correct |
35 |
Incorrect |
24 ms |
8784 KB |
Output isn't correct |
36 |
Correct |
8 ms |
8784 KB |
Output is correct |
37 |
Incorrect |
8 ms |
8784 KB |
Output isn't correct |
38 |
Incorrect |
32 ms |
8852 KB |
Output isn't correct |
39 |
Correct |
10 ms |
8784 KB |
Output is correct |
40 |
Incorrect |
10 ms |
8784 KB |
Output isn't correct |
41 |
Incorrect |
38 ms |
8784 KB |
Output isn't correct |
42 |
Correct |
15 ms |
8784 KB |
Output is correct |
43 |
Incorrect |
12 ms |
8784 KB |
Output isn't correct |
44 |
Incorrect |
55 ms |
8848 KB |
Output isn't correct |
45 |
Correct |
14 ms |
8784 KB |
Output is correct |
46 |
Incorrect |
14 ms |
8784 KB |
Output isn't correct |
47 |
Incorrect |
60 ms |
8784 KB |
Output isn't correct |
48 |
Correct |
17 ms |
8784 KB |
Output is correct |
49 |
Incorrect |
17 ms |
8784 KB |
Output isn't correct |
50 |
Incorrect |
86 ms |
8784 KB |
Output isn't correct |
51 |
Correct |
21 ms |
8784 KB |
Output is correct |
52 |
Incorrect |
19 ms |
8784 KB |
Output isn't correct |
53 |
Incorrect |
93 ms |
8784 KB |
Output isn't correct |
54 |
Correct |
21 ms |
8784 KB |
Output is correct |
55 |
Incorrect |
22 ms |
8784 KB |
Output isn't correct |
56 |
Incorrect |
89 ms |
8628 KB |
Output isn't correct |
57 |
Correct |
24 ms |
8784 KB |
Output is correct |
58 |
Incorrect |
24 ms |
8784 KB |
Output isn't correct |
59 |
Incorrect |
105 ms |
8868 KB |
Output isn't correct |
60 |
Correct |
26 ms |
8784 KB |
Output is correct |
61 |
Incorrect |
27 ms |
8784 KB |
Output isn't correct |
62 |
Incorrect |
132 ms |
8784 KB |
Output isn't correct |
63 |
Correct |
87 ms |
9032 KB |
Output is correct |
64 |
Incorrect |
245 ms |
8784 KB |
Output isn't correct |
65 |
Correct |
132 ms |
8784 KB |
Output is correct |
66 |
Correct |
96 ms |
8952 KB |
Output is correct |
67 |
Correct |
89 ms |
8784 KB |
Output is correct |
68 |
Incorrect |
182 ms |
8784 KB |
Output isn't correct |
69 |
Incorrect |
173 ms |
8884 KB |
Output isn't correct |
70 |
Incorrect |
213 ms |
8784 KB |
Output isn't correct |
71 |
Incorrect |
192 ms |
8904 KB |
Output isn't correct |
72 |
Incorrect |
48 ms |
8784 KB |
Output isn't correct |
73 |
Incorrect |
144 ms |
9040 KB |
Output isn't correct |
74 |
Incorrect |
110 ms |
9040 KB |
Output isn't correct |
75 |
Incorrect |
140 ms |
9040 KB |
Output isn't correct |
76 |
Incorrect |
135 ms |
9052 KB |
Output isn't correct |
77 |
Incorrect |
130 ms |
9040 KB |
Output isn't correct |
78 |
Incorrect |
160 ms |
9288 KB |
Output isn't correct |
79 |
Incorrect |
136 ms |
9040 KB |
Output isn't correct |
80 |
Incorrect |
128 ms |
9040 KB |
Output isn't correct |
81 |
Incorrect |
114 ms |
9212 KB |
Output isn't correct |
82 |
Incorrect |
130 ms |
9040 KB |
Output isn't correct |
83 |
Incorrect |
161 ms |
9040 KB |
Output isn't correct |
84 |
Incorrect |
140 ms |
9144 KB |
Output isn't correct |
85 |
Incorrect |
105 ms |
9160 KB |
Output isn't correct |
86 |
Incorrect |
141 ms |
9040 KB |
Output isn't correct |
87 |
Incorrect |
137 ms |
8984 KB |
Output isn't correct |
88 |
Incorrect |
155 ms |
9056 KB |
Output isn't correct |
89 |
Incorrect |
149 ms |
9040 KB |
Output isn't correct |
90 |
Incorrect |
177 ms |
9040 KB |
Output isn't correct |
91 |
Incorrect |
151 ms |
9040 KB |
Output isn't correct |
92 |
Incorrect |
159 ms |
9040 KB |
Output isn't correct |