# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1071998 |
2024-08-23T13:10:48 Z |
7again |
Mecho (IOI09_mecho) |
C++17 |
|
427 ms |
11936 KB |
#include <bits/stdc++.h>
using namespace std ;
const int N = 801 ;
int dx[]{0 , 0 , 1 , -1} ;
int dy[]{1 , -1 , 0 , 0} ;
int n , s ;
pair <int , int> Honey , Home ;
char a[N][N] ;
bool inside(int x , int y) {
return (x >= 0 && y >= 0 && x < n && y < n && a[x][y] != 'T') ;
}
bool val(int x , int y) {
return x / s < y ;
}
int ok(int time) {
int mn2[n][n] ;
fill_n(&mn2[0][0] , n*n , 1e9) ;
queue<pair <int , int>> q2 ;
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j < n ; j++) {
if(a[i][j] == 'H') {
q2.push({i, j}) ;
mn2[i][j] = 0 ;
}
}
}
while(q2.size()) {
pair <int , int> t = q2.front() ;
q2.pop() ;
for(int i = 0 ; i < 4 ; i++) {
int x = t.first + dx[i] ;
int y = t.second + dy[i] ;
if(inside(x , y) && mn2[t.first][t.second] + 1 < mn2[x][y]) {
mn2[x][y] = mn2[t.first][t.second] + 1 ;
q2.push({x, y}) ;
}
}
}
int mn[n][n] ;
fill_n(&mn[0][0] , n * n , 1e9 ) ;
queue <pair <int , int>> q ;
mn[Honey.first][Honey.second] = 0 ;
if(mn2[Honey.first][Honey.second] > time)
q.push(Honey) ;
while(!q.empty()) {
pair <int , int> t = q.front() ;
q.pop() ;
for(int i = 0 ; i < 4 ; i++) {
int x = t.first + dx[i] ;
int y = t.second + dy[i] ;
if(val(mn[t.first][t.second] + 1 , mn2[x][y] - time) && inside(x , y) && mn[t.first][t.second] + 1 < mn[x][y]) {
mn[x][y] = mn[t.first][t.second] + 1 ;
q.push({x , y}) ;
}
}
}
if(mn[Home.first][Home.second] == 1e9)
return 0 ;
return 1 ;
}
int main() {
cin >> n >> s ;
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j < n ; j++) {
cin >> a[i][j] ;
if(a[i][j] == 'M')
Honey = {i , j} ;
if(a[i][j] == 'D')
Home = {i , j} ;
}
}
int l = 0 , r = n * n + 1 ;
while(l + 1 < r) {
int m = (l + r) / 2 ;
if(ok(m))
l = m ;
else
r = m ;
}
cout << l << endl ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
270 ms |
6168 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
536 KB |
Output is correct |
33 |
Correct |
27 ms |
1664 KB |
Output is correct |
34 |
Correct |
21 ms |
1628 KB |
Output is correct |
35 |
Correct |
41 ms |
1444 KB |
Output is correct |
36 |
Correct |
28 ms |
1884 KB |
Output is correct |
37 |
Correct |
29 ms |
1884 KB |
Output is correct |
38 |
Correct |
52 ms |
1884 KB |
Output is correct |
39 |
Correct |
34 ms |
2140 KB |
Output is correct |
40 |
Correct |
34 ms |
2140 KB |
Output is correct |
41 |
Correct |
78 ms |
2364 KB |
Output is correct |
42 |
Correct |
47 ms |
2648 KB |
Output is correct |
43 |
Correct |
44 ms |
2652 KB |
Output is correct |
44 |
Correct |
87 ms |
2652 KB |
Output is correct |
45 |
Correct |
55 ms |
3160 KB |
Output is correct |
46 |
Correct |
54 ms |
3032 KB |
Output is correct |
47 |
Correct |
108 ms |
3228 KB |
Output is correct |
48 |
Correct |
63 ms |
3676 KB |
Output is correct |
49 |
Correct |
61 ms |
3672 KB |
Output is correct |
50 |
Correct |
165 ms |
3676 KB |
Output is correct |
51 |
Correct |
76 ms |
4188 KB |
Output is correct |
52 |
Correct |
78 ms |
4024 KB |
Output is correct |
53 |
Runtime error |
134 ms |
8272 KB |
Execution killed with signal 11 |
54 |
Correct |
104 ms |
4692 KB |
Output is correct |
55 |
Correct |
87 ms |
4696 KB |
Output is correct |
56 |
Runtime error |
163 ms |
9300 KB |
Execution killed with signal 11 |
57 |
Correct |
103 ms |
5212 KB |
Output is correct |
58 |
Correct |
100 ms |
5272 KB |
Output is correct |
59 |
Correct |
218 ms |
5204 KB |
Output is correct |
60 |
Correct |
114 ms |
6040 KB |
Output is correct |
61 |
Correct |
117 ms |
5968 KB |
Output is correct |
62 |
Correct |
235 ms |
5980 KB |
Output is correct |
63 |
Runtime error |
153 ms |
11912 KB |
Execution killed with signal 11 |
64 |
Runtime error |
124 ms |
11860 KB |
Execution killed with signal 11 |
65 |
Correct |
335 ms |
6048 KB |
Output is correct |
66 |
Correct |
330 ms |
5864 KB |
Output is correct |
67 |
Runtime error |
127 ms |
11936 KB |
Execution killed with signal 11 |
68 |
Correct |
307 ms |
5972 KB |
Output is correct |
69 |
Correct |
295 ms |
6080 KB |
Output is correct |
70 |
Correct |
318 ms |
6080 KB |
Output is correct |
71 |
Correct |
309 ms |
5884 KB |
Output is correct |
72 |
Correct |
291 ms |
5872 KB |
Output is correct |
73 |
Correct |
277 ms |
6328 KB |
Output is correct |
74 |
Correct |
355 ms |
6132 KB |
Output is correct |
75 |
Correct |
374 ms |
6332 KB |
Output is correct |
76 |
Correct |
331 ms |
6232 KB |
Output is correct |
77 |
Correct |
427 ms |
6276 KB |
Output is correct |
78 |
Incorrect |
273 ms |
6300 KB |
Output isn't correct |
79 |
Correct |
254 ms |
6300 KB |
Output is correct |
80 |
Correct |
262 ms |
6308 KB |
Output is correct |
81 |
Correct |
277 ms |
6116 KB |
Output is correct |
82 |
Correct |
275 ms |
6112 KB |
Output is correct |
83 |
Correct |
277 ms |
6236 KB |
Output is correct |
84 |
Correct |
323 ms |
6316 KB |
Output is correct |
85 |
Correct |
292 ms |
6228 KB |
Output is correct |
86 |
Correct |
289 ms |
6228 KB |
Output is correct |
87 |
Correct |
275 ms |
6228 KB |
Output is correct |
88 |
Correct |
285 ms |
6212 KB |
Output is correct |
89 |
Correct |
340 ms |
6224 KB |
Output is correct |
90 |
Correct |
291 ms |
5972 KB |
Output is correct |
91 |
Correct |
282 ms |
6212 KB |
Output is correct |
92 |
Correct |
275 ms |
5968 KB |
Output is correct |