# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
972907 |
2024-05-01T10:11:15 Z |
jadai007 |
Mecho (IOI09_mecho) |
C++17 |
|
661 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) bee[i][j] = bear[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);
}
}
}
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') 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};
}
}
int l = 1, r = 1e9;
while(l <= r){
int mid = (l + r) >> 1;
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:38:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
38 | if (w%s == 0) if((w+s-1)/s >= bee[x][y]) continue;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 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 |
1 ms |
4444 KB |
Output isn't correct |
7 |
Runtime error |
137 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
4440 KB |
Output isn't correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Runtime error |
137 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
20 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
22 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
24 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
25 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
26 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
28 |
Incorrect |
4 ms |
4444 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
30 |
Incorrect |
3 ms |
4440 KB |
Output isn't correct |
31 |
Incorrect |
3 ms |
4696 KB |
Output isn't correct |
32 |
Incorrect |
5 ms |
4444 KB |
Output isn't correct |
33 |
Incorrect |
33 ms |
4700 KB |
Output isn't correct |
34 |
Incorrect |
39 ms |
4700 KB |
Output isn't correct |
35 |
Runtime error |
153 ms |
65536 KB |
Execution killed with signal 9 |
36 |
Incorrect |
44 ms |
4900 KB |
Output isn't correct |
37 |
Incorrect |
53 ms |
4700 KB |
Output isn't correct |
38 |
Runtime error |
156 ms |
65536 KB |
Execution killed with signal 9 |
39 |
Incorrect |
54 ms |
4956 KB |
Output isn't correct |
40 |
Incorrect |
57 ms |
4952 KB |
Output isn't correct |
41 |
Runtime error |
163 ms |
65536 KB |
Execution killed with signal 9 |
42 |
Incorrect |
68 ms |
5208 KB |
Output isn't correct |
43 |
Incorrect |
77 ms |
5212 KB |
Output isn't correct |
44 |
Runtime error |
156 ms |
65536 KB |
Execution killed with signal 9 |
45 |
Incorrect |
82 ms |
5212 KB |
Output isn't correct |
46 |
Incorrect |
94 ms |
5716 KB |
Output isn't correct |
47 |
Runtime error |
192 ms |
65536 KB |
Execution killed with signal 9 |
48 |
Incorrect |
95 ms |
5720 KB |
Output isn't correct |
49 |
Incorrect |
105 ms |
5548 KB |
Output isn't correct |
50 |
Runtime error |
152 ms |
65536 KB |
Execution killed with signal 9 |
51 |
Incorrect |
111 ms |
5696 KB |
Output isn't correct |
52 |
Incorrect |
120 ms |
5468 KB |
Output isn't correct |
53 |
Runtime error |
167 ms |
65536 KB |
Execution killed with signal 9 |
54 |
Incorrect |
130 ms |
5724 KB |
Output isn't correct |
55 |
Incorrect |
151 ms |
5724 KB |
Output isn't correct |
56 |
Runtime error |
177 ms |
65536 KB |
Execution killed with signal 9 |
57 |
Incorrect |
166 ms |
6008 KB |
Output isn't correct |
58 |
Incorrect |
163 ms |
5992 KB |
Output isn't correct |
59 |
Runtime error |
188 ms |
65536 KB |
Execution killed with signal 9 |
60 |
Incorrect |
169 ms |
5976 KB |
Output isn't correct |
61 |
Incorrect |
191 ms |
6180 KB |
Output isn't correct |
62 |
Runtime error |
206 ms |
65536 KB |
Execution killed with signal 9 |
63 |
Correct |
471 ms |
5980 KB |
Output is correct |
64 |
Incorrect |
634 ms |
6176 KB |
Output isn't correct |
65 |
Incorrect |
542 ms |
6180 KB |
Output isn't correct |
66 |
Correct |
503 ms |
6172 KB |
Output is correct |
67 |
Incorrect |
484 ms |
6168 KB |
Output isn't correct |
68 |
Incorrect |
646 ms |
6232 KB |
Output isn't correct |
69 |
Incorrect |
623 ms |
6236 KB |
Output isn't correct |
70 |
Incorrect |
661 ms |
6236 KB |
Output isn't correct |
71 |
Incorrect |
651 ms |
6232 KB |
Output isn't correct |
72 |
Incorrect |
624 ms |
6236 KB |
Output isn't correct |
73 |
Runtime error |
170 ms |
65536 KB |
Execution killed with signal 9 |
74 |
Runtime error |
143 ms |
65536 KB |
Execution killed with signal 9 |
75 |
Runtime error |
159 ms |
65536 KB |
Execution killed with signal 9 |
76 |
Runtime error |
145 ms |
65536 KB |
Execution killed with signal 9 |
77 |
Runtime error |
174 ms |
65536 KB |
Execution killed with signal 9 |
78 |
Runtime error |
140 ms |
65536 KB |
Execution killed with signal 9 |
79 |
Runtime error |
138 ms |
65536 KB |
Execution killed with signal 9 |
80 |
Runtime error |
142 ms |
65536 KB |
Execution killed with signal 9 |
81 |
Runtime error |
178 ms |
65536 KB |
Execution killed with signal 9 |
82 |
Runtime error |
154 ms |
65536 KB |
Execution killed with signal 9 |
83 |
Runtime error |
157 ms |
65536 KB |
Execution killed with signal 9 |
84 |
Runtime error |
151 ms |
65536 KB |
Execution killed with signal 9 |
85 |
Runtime error |
149 ms |
65536 KB |
Execution killed with signal 9 |
86 |
Runtime error |
147 ms |
65536 KB |
Execution killed with signal 9 |
87 |
Runtime error |
161 ms |
65536 KB |
Execution killed with signal 9 |
88 |
Runtime error |
142 ms |
65536 KB |
Execution killed with signal 9 |
89 |
Runtime error |
141 ms |
65536 KB |
Execution killed with signal 9 |
90 |
Runtime error |
164 ms |
65536 KB |
Execution killed with signal 9 |
91 |
Runtime error |
139 ms |
65536 KB |
Execution killed with signal 9 |
92 |
Runtime error |
138 ms |
65536 KB |
Execution killed with signal 9 |