# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
972886 |
2024-05-01T09:31:24 Z |
jadai007 |
Mecho (IOI09_mecho) |
C++17 |
|
579 ms |
7108 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;
q.emplace(start.first, start.second, mid);
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;
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){
int times = ((w + 1) / s) + ((w + 1) % s != 0);
if(bee[nx][ny] <= times) continue;
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;
//cout << mid << ' ';
if(solve(mid)){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
418 ms |
6484 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
25 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
4952 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
33 |
Incorrect |
31 ms |
5012 KB |
Output isn't correct |
34 |
Incorrect |
33 ms |
4700 KB |
Output isn't correct |
35 |
Incorrect |
65 ms |
4836 KB |
Output isn't correct |
36 |
Incorrect |
40 ms |
4952 KB |
Output isn't correct |
37 |
Incorrect |
42 ms |
4956 KB |
Output isn't correct |
38 |
Incorrect |
89 ms |
4956 KB |
Output isn't correct |
39 |
Incorrect |
54 ms |
5212 KB |
Output isn't correct |
40 |
Incorrect |
54 ms |
5212 KB |
Output isn't correct |
41 |
Incorrect |
112 ms |
5232 KB |
Output isn't correct |
42 |
Incorrect |
61 ms |
5212 KB |
Output isn't correct |
43 |
Incorrect |
70 ms |
5212 KB |
Output isn't correct |
44 |
Incorrect |
136 ms |
5208 KB |
Output isn't correct |
45 |
Incorrect |
76 ms |
5468 KB |
Output isn't correct |
46 |
Incorrect |
82 ms |
5576 KB |
Output isn't correct |
47 |
Incorrect |
161 ms |
5608 KB |
Output isn't correct |
48 |
Incorrect |
89 ms |
5780 KB |
Output isn't correct |
49 |
Incorrect |
97 ms |
5724 KB |
Output isn't correct |
50 |
Incorrect |
190 ms |
5720 KB |
Output isn't correct |
51 |
Incorrect |
104 ms |
5976 KB |
Output isn't correct |
52 |
Incorrect |
115 ms |
5724 KB |
Output isn't correct |
53 |
Incorrect |
239 ms |
6228 KB |
Output isn't correct |
54 |
Incorrect |
123 ms |
5976 KB |
Output isn't correct |
55 |
Incorrect |
130 ms |
6188 KB |
Output isn't correct |
56 |
Incorrect |
284 ms |
6224 KB |
Output isn't correct |
57 |
Incorrect |
144 ms |
6340 KB |
Output isn't correct |
58 |
Incorrect |
161 ms |
6380 KB |
Output isn't correct |
59 |
Incorrect |
342 ms |
6480 KB |
Output isn't correct |
60 |
Incorrect |
160 ms |
6592 KB |
Output isn't correct |
61 |
Incorrect |
166 ms |
6492 KB |
Output isn't correct |
62 |
Incorrect |
366 ms |
6592 KB |
Output isn't correct |
63 |
Correct |
461 ms |
6488 KB |
Output is correct |
64 |
Incorrect |
579 ms |
6740 KB |
Output isn't correct |
65 |
Incorrect |
516 ms |
6736 KB |
Output isn't correct |
66 |
Incorrect |
477 ms |
6552 KB |
Output isn't correct |
67 |
Incorrect |
472 ms |
6580 KB |
Output isn't correct |
68 |
Correct |
484 ms |
6648 KB |
Output is correct |
69 |
Incorrect |
471 ms |
6600 KB |
Output isn't correct |
70 |
Incorrect |
477 ms |
6740 KB |
Output isn't correct |
71 |
Incorrect |
450 ms |
6488 KB |
Output isn't correct |
72 |
Incorrect |
466 ms |
6640 KB |
Output isn't correct |
73 |
Incorrect |
381 ms |
7008 KB |
Output isn't correct |
74 |
Incorrect |
400 ms |
7000 KB |
Output isn't correct |
75 |
Incorrect |
410 ms |
7040 KB |
Output isn't correct |
76 |
Incorrect |
404 ms |
6748 KB |
Output isn't correct |
77 |
Incorrect |
410 ms |
7024 KB |
Output isn't correct |
78 |
Incorrect |
381 ms |
6744 KB |
Output isn't correct |
79 |
Incorrect |
388 ms |
7000 KB |
Output isn't correct |
80 |
Incorrect |
371 ms |
6912 KB |
Output isn't correct |
81 |
Incorrect |
368 ms |
6944 KB |
Output isn't correct |
82 |
Incorrect |
388 ms |
6748 KB |
Output isn't correct |
83 |
Correct |
406 ms |
6900 KB |
Output is correct |
84 |
Incorrect |
412 ms |
6528 KB |
Output isn't correct |
85 |
Incorrect |
386 ms |
6748 KB |
Output isn't correct |
86 |
Incorrect |
388 ms |
6744 KB |
Output isn't correct |
87 |
Incorrect |
410 ms |
6748 KB |
Output isn't correct |
88 |
Correct |
395 ms |
6848 KB |
Output is correct |
89 |
Incorrect |
396 ms |
6740 KB |
Output isn't correct |
90 |
Incorrect |
402 ms |
6992 KB |
Output isn't correct |
91 |
Incorrect |
390 ms |
6824 KB |
Output isn't correct |
92 |
Incorrect |
394 ms |
7108 KB |
Output isn't correct |