# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
103999 |
2019-04-03T16:22:40 Z |
Badral |
Mecho (IOI09_mecho) |
C++17 |
|
348 ms |
14536 KB |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define pi pair<ll, ll>
char a[1015][1015];
ll dx[] = {0, 0, 0, 1, -1, -1, 1, 1, -1};
ll dy[] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
ll bear[1105][1015], bee[1105][1015], xx = -1, yy = -1, xxx = -1, yyy = -1, n, kk;
bool asdasd = 0;
bool can(ll k) {
if ( k >= bee[xx][yy] ) return 0;
for ( ll i = 1; i <= n; i++ )
for ( ll j = 1; j <= n; j++ )
bear[i][j] = INT_MAX;
bear[xx][yy] = 0;
queue < pi > q;
q.push(make_pair(xx, yy));
ll x, y;
while(!q.empty()) {
tie(x, y) = q.front();
q.pop();
for(ll i = 1; i <= 4; i++) {
ll x1 = x + dx[i], y1 = y + dy[i];
if ( a[x1][y1] == 'D' ) {asdasd = 1; return 1;}
if ( a[x1][y1] == 'G' && bear[x][y] + 1 <= kk * ( bee[x1][y1] - k ) && bear[x1][y1] == INT_MAX ) {
bear[x1][y1] = bear[x][y] + 1;
q.push ( make_pair ( x1, y1 ) );
}
}
}
return 0;
}
int main() {
cin >> n >> kk;
queue < pi > p;
for(ll i = 1; i <= n; i++) {
for(ll j = 1; j <= n; j++) {
bee[i][j] = INT_MAX;
cin >>a[i][j];
if ( a[i][j] == 'H' ) {p.push(make_pair(i, j)); bee[i][j] = 0;}
if ( a[i][j] == 'M' ) xx = i, yy = j;
}
}
while(!p.empty()) {
ll x, y; tie(x, y) = p.front(); p.pop();
for ( ll i = 1; i <= 4; i++ ) {
ll x1 = x + dx[i], y1 = y + dy[i];
if ( bee[x1][y1] == INT_MAX && ( a[x1][y1] == 'G' || a[x1][y1] == 'M' ) ) {
bee[x1][y1] = bee[x][y] + 1; p.push ( make_pair ( x1, y1 ) );
}
}
}
ll k = 0, mm = n * n;
for(ll i = mm/2; i >= 1; i /= 2)
while(i + k <= mm && can(i+k))
k += i;
if ( !asdasd ) cout << -1;
else cout << k;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
266 ms |
14072 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
896 KB |
Output is correct |
13 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
14 |
Correct |
3 ms |
896 KB |
Output is correct |
15 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Incorrect |
3 ms |
640 KB |
Output isn't correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Incorrect |
2 ms |
768 KB |
Output isn't correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Incorrect |
3 ms |
896 KB |
Output isn't correct |
26 |
Correct |
3 ms |
896 KB |
Output is correct |
27 |
Incorrect |
3 ms |
1024 KB |
Output isn't correct |
28 |
Correct |
3 ms |
1024 KB |
Output is correct |
29 |
Incorrect |
3 ms |
1024 KB |
Output isn't correct |
30 |
Correct |
3 ms |
1024 KB |
Output is correct |
31 |
Incorrect |
3 ms |
1152 KB |
Output isn't correct |
32 |
Correct |
4 ms |
1024 KB |
Output is correct |
33 |
Incorrect |
14 ms |
5376 KB |
Output isn't correct |
34 |
Correct |
16 ms |
5504 KB |
Output is correct |
35 |
Correct |
39 ms |
5496 KB |
Output is correct |
36 |
Incorrect |
17 ms |
6400 KB |
Output isn't correct |
37 |
Correct |
20 ms |
6400 KB |
Output is correct |
38 |
Correct |
48 ms |
6392 KB |
Output is correct |
39 |
Incorrect |
22 ms |
7552 KB |
Output isn't correct |
40 |
Correct |
22 ms |
7544 KB |
Output is correct |
41 |
Correct |
73 ms |
7524 KB |
Output is correct |
42 |
Incorrect |
29 ms |
8696 KB |
Output isn't correct |
43 |
Correct |
28 ms |
8704 KB |
Output is correct |
44 |
Correct |
86 ms |
8832 KB |
Output is correct |
45 |
Incorrect |
32 ms |
9592 KB |
Output isn't correct |
46 |
Correct |
31 ms |
9592 KB |
Output is correct |
47 |
Correct |
116 ms |
9592 KB |
Output is correct |
48 |
Incorrect |
42 ms |
10488 KB |
Output isn't correct |
49 |
Correct |
41 ms |
10488 KB |
Output is correct |
50 |
Correct |
142 ms |
10488 KB |
Output is correct |
51 |
Incorrect |
40 ms |
11376 KB |
Output isn't correct |
52 |
Correct |
41 ms |
11256 KB |
Output is correct |
53 |
Correct |
167 ms |
11380 KB |
Output is correct |
54 |
Incorrect |
50 ms |
12172 KB |
Output isn't correct |
55 |
Correct |
52 ms |
12252 KB |
Output is correct |
56 |
Correct |
211 ms |
12152 KB |
Output is correct |
57 |
Incorrect |
54 ms |
12920 KB |
Output isn't correct |
58 |
Correct |
59 ms |
13020 KB |
Output is correct |
59 |
Correct |
241 ms |
13076 KB |
Output is correct |
60 |
Incorrect |
62 ms |
13820 KB |
Output isn't correct |
61 |
Correct |
65 ms |
13816 KB |
Output is correct |
62 |
Correct |
255 ms |
13892 KB |
Output is correct |
63 |
Incorrect |
167 ms |
13944 KB |
Output isn't correct |
64 |
Correct |
348 ms |
13884 KB |
Output is correct |
65 |
Correct |
262 ms |
13880 KB |
Output is correct |
66 |
Incorrect |
255 ms |
13944 KB |
Output isn't correct |
67 |
Correct |
191 ms |
13816 KB |
Output is correct |
68 |
Incorrect |
123 ms |
13944 KB |
Output isn't correct |
69 |
Correct |
108 ms |
13944 KB |
Output is correct |
70 |
Correct |
91 ms |
13816 KB |
Output is correct |
71 |
Correct |
113 ms |
13864 KB |
Output is correct |
72 |
Correct |
78 ms |
13816 KB |
Output is correct |
73 |
Correct |
86 ms |
14404 KB |
Output is correct |
74 |
Correct |
144 ms |
14272 KB |
Output is correct |
75 |
Correct |
180 ms |
14272 KB |
Output is correct |
76 |
Correct |
165 ms |
14400 KB |
Output is correct |
77 |
Correct |
217 ms |
14428 KB |
Output is correct |
78 |
Correct |
205 ms |
14324 KB |
Output is correct |
79 |
Correct |
108 ms |
14320 KB |
Output is correct |
80 |
Correct |
160 ms |
14536 KB |
Output is correct |
81 |
Correct |
137 ms |
14320 KB |
Output is correct |
82 |
Correct |
131 ms |
14336 KB |
Output is correct |
83 |
Incorrect |
154 ms |
14280 KB |
Output isn't correct |
84 |
Correct |
151 ms |
14200 KB |
Output is correct |
85 |
Correct |
184 ms |
14288 KB |
Output is correct |
86 |
Correct |
161 ms |
14428 KB |
Output is correct |
87 |
Correct |
222 ms |
14244 KB |
Output is correct |
88 |
Incorrect |
182 ms |
14196 KB |
Output isn't correct |
89 |
Correct |
269 ms |
14324 KB |
Output is correct |
90 |
Correct |
221 ms |
14200 KB |
Output is correct |
91 |
Correct |
252 ms |
14196 KB |
Output is correct |
92 |
Correct |
183 ms |
14324 KB |
Output is correct |