# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
972934 |
2024-05-01T10:29:43 Z |
jadai007 |
Mecho (IOI09_mecho) |
C++17 |
|
261 ms |
65536 KB |
#include<bits/stdc++.h>
using namespace std;
int n,s, bee[808][808], xx[] = {0, 0, -1, 1}, xy[] = {-1, 1, 0, 0}, bear[808][808], ans;
char mp[808][808];
pair<int, int> start, en;
queue<tuple<int, int, int>> q;
bool solve(int mid){
for(int i = 1; i<=n; ++i) for(int j = 1; j<=n; ++j) bear[i][j] = 1e9;
bear[start.first][start.second] = mid*s;
q.emplace(start.first, start.second, mid*s);
while(!q.empty()){
int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop();
if(x == en.first && y == en.second) return true;
if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue;
else if((w+s-1)/s > bee[x][y]) continue;
bear[x][y] = w;
for(int i = 0; i<4; ++i){
int nx = x + xx[i];
int ny = y + xy[i];
if(nx < 1 || ny < 1 || nx > n || ny > n || mp[nx][ny] == 'T' || mp[nx][ny] == 'H') continue;
if(bear[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];
if(mp[i][j] == 'M') start = {i, j};
else if(mp[i][j] == 'D') en = {i, j};
}
}
for(int i = 1; i<=n; ++i) for(int j = 1; j<=n; ++j) bee[i][j] = 1e9;
for(int i = 1; i<=n; ++i){
for(int j = 1; j<=n; ++j){
if(mp[i][j] == 'H'){
bee[i][j] = 0;
q.emplace(i, j, 0);
}
}
}
while(!q.empty()){
int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front());
q.pop();
for(int i = 0; i<4; ++i){
int nx = x + xx[i];
int ny = y + xy[i];
if(nx < 1 || n < 1 || nx > n || ny > n || mp[nx][ny] == 'T') continue;
if(bee[nx][ny] > w + 1){
bee[nx][ny] = w + 1;
q.emplace(nx, ny, w + 1);
}
}
}
int l = 1, r = 1e9;
while(l <= r){
int mid = (l + r) >> 1;
while(!q.empty()) q.pop();
if(solve(mid)){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans;
}
Compilation message
mecho.cpp: In function 'bool solve(int)':
mecho.cpp:17:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
17 | if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
7 |
Runtime error |
159 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Incorrect |
1 ms |
4696 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
4444 KB |
Output isn't correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Incorrect |
1 ms |
4580 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Runtime error |
133 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
33 |
Correct |
5 ms |
4700 KB |
Output is correct |
34 |
Incorrect |
5 ms |
4700 KB |
Output isn't correct |
35 |
Runtime error |
146 ms |
65536 KB |
Execution killed with signal 9 |
36 |
Correct |
7 ms |
4696 KB |
Output is correct |
37 |
Incorrect |
7 ms |
4700 KB |
Output isn't correct |
38 |
Runtime error |
144 ms |
65536 KB |
Execution killed with signal 9 |
39 |
Correct |
8 ms |
4952 KB |
Output is correct |
40 |
Incorrect |
9 ms |
4956 KB |
Output isn't correct |
41 |
Runtime error |
179 ms |
65536 KB |
Execution killed with signal 9 |
42 |
Correct |
11 ms |
5208 KB |
Output is correct |
43 |
Incorrect |
10 ms |
5212 KB |
Output isn't correct |
44 |
Runtime error |
155 ms |
65536 KB |
Execution killed with signal 9 |
45 |
Correct |
12 ms |
5208 KB |
Output is correct |
46 |
Incorrect |
12 ms |
5292 KB |
Output isn't correct |
47 |
Runtime error |
188 ms |
65536 KB |
Execution killed with signal 9 |
48 |
Correct |
14 ms |
5464 KB |
Output is correct |
49 |
Incorrect |
14 ms |
5560 KB |
Output isn't correct |
50 |
Runtime error |
168 ms |
65536 KB |
Execution killed with signal 9 |
51 |
Correct |
16 ms |
5664 KB |
Output is correct |
52 |
Incorrect |
17 ms |
5708 KB |
Output isn't correct |
53 |
Runtime error |
165 ms |
65536 KB |
Execution killed with signal 9 |
54 |
Correct |
18 ms |
5720 KB |
Output is correct |
55 |
Incorrect |
19 ms |
5976 KB |
Output isn't correct |
56 |
Runtime error |
200 ms |
65536 KB |
Execution killed with signal 9 |
57 |
Correct |
21 ms |
6024 KB |
Output is correct |
58 |
Incorrect |
29 ms |
5980 KB |
Output isn't correct |
59 |
Runtime error |
192 ms |
65536 KB |
Execution killed with signal 9 |
60 |
Correct |
24 ms |
5976 KB |
Output is correct |
61 |
Incorrect |
25 ms |
5976 KB |
Output isn't correct |
62 |
Runtime error |
194 ms |
65536 KB |
Execution killed with signal 9 |
63 |
Correct |
84 ms |
5980 KB |
Output is correct |
64 |
Incorrect |
261 ms |
5980 KB |
Output isn't correct |
65 |
Incorrect |
145 ms |
6172 KB |
Output isn't correct |
66 |
Correct |
104 ms |
5980 KB |
Output is correct |
67 |
Incorrect |
111 ms |
6228 KB |
Output isn't correct |
68 |
Incorrect |
203 ms |
6212 KB |
Output isn't correct |
69 |
Incorrect |
183 ms |
6236 KB |
Output isn't correct |
70 |
Incorrect |
224 ms |
6236 KB |
Output isn't correct |
71 |
Incorrect |
214 ms |
6236 KB |
Output isn't correct |
72 |
Incorrect |
43 ms |
6232 KB |
Output isn't correct |
73 |
Runtime error |
160 ms |
65536 KB |
Execution killed with signal 9 |
74 |
Runtime error |
182 ms |
65536 KB |
Execution killed with signal 9 |
75 |
Runtime error |
148 ms |
65536 KB |
Execution killed with signal 9 |
76 |
Runtime error |
152 ms |
65536 KB |
Execution killed with signal 9 |
77 |
Runtime error |
164 ms |
65536 KB |
Execution killed with signal 9 |
78 |
Runtime error |
144 ms |
65536 KB |
Execution killed with signal 9 |
79 |
Runtime error |
144 ms |
65536 KB |
Execution killed with signal 9 |
80 |
Runtime error |
149 ms |
65536 KB |
Execution killed with signal 9 |
81 |
Runtime error |
161 ms |
65536 KB |
Execution killed with signal 9 |
82 |
Runtime error |
156 ms |
65536 KB |
Execution killed with signal 9 |
83 |
Runtime error |
155 ms |
65536 KB |
Execution killed with signal 9 |
84 |
Runtime error |
159 ms |
65536 KB |
Execution killed with signal 9 |
85 |
Runtime error |
152 ms |
65536 KB |
Execution killed with signal 9 |
86 |
Runtime error |
156 ms |
65536 KB |
Execution killed with signal 9 |
87 |
Runtime error |
155 ms |
65536 KB |
Execution killed with signal 9 |
88 |
Runtime error |
141 ms |
65536 KB |
Execution killed with signal 9 |
89 |
Runtime error |
153 ms |
65536 KB |
Execution killed with signal 9 |
90 |
Runtime error |
141 ms |
65536 KB |
Execution killed with signal 9 |
91 |
Runtime error |
144 ms |
65536 KB |
Execution killed with signal 9 |
92 |
Runtime error |
143 ms |
65536 KB |
Execution killed with signal 9 |