# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
104007 |
2019-04-03T16:38:47 Z |
Badral |
Mecho (IOI09_mecho) |
C++17 |
|
319 ms |
7900 KB |
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
char a[1015][1015];
int dx[] = {0, 0, 0, 1, -1, -1, 1, 1, -1};
int dy[] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
int bear[1105][1015], bee[1105][1015], xx = -1, yy = -1, xxx = -1, yyy = -1, n, kk;
bool asdasd = 0;
bool can(int k) {
if ( k >= bee[xx][yy] ) return 0;
for ( int i = 1; i <= n; i++ )
for ( int j = 1; j <= n; j++ )
bear[i][j] = INT_MAX;
bear[xx][yy] = 0;
queue < pi > q;
q.push(make_pair(xx, yy));
int x, y;
while(!q.empty()) {
tie(x, y) = q.front();
q.pop();
for(int i = 1; i <= 4; i++) {
int 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(int i = 1; i <= n; i++) {
for(int 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()) {
int x, y; tie(x, y) = p.front(); p.pop();
for ( int i = 1; i <= 4; i++ ) {
int 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 ) );
}
}
}
int k = 0, mm = n * n;
for(int i = mm/2; i >= 1; i /= 2)
while(i + k <= mm && can(i+k))
k += i;
bool pppp = can(0);
if ( !asdasd ) cout << -1;
else cout << k;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:68:10: warning: unused variable 'pppp' [-Wunused-variable]
bool pppp = can(0);
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
319 ms |
7416 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
896 KB |
Output is correct |
13 |
Correct |
2 ms |
768 KB |
Output is correct |
14 |
Correct |
4 ms |
896 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
2 ms |
640 KB |
Output is correct |
20 |
Correct |
3 ms |
640 KB |
Output is correct |
21 |
Correct |
3 ms |
768 KB |
Output is correct |
22 |
Correct |
2 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
816 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
3 ms |
896 KB |
Output is correct |
26 |
Correct |
3 ms |
896 KB |
Output is correct |
27 |
Correct |
2 ms |
896 KB |
Output is correct |
28 |
Correct |
3 ms |
896 KB |
Output is correct |
29 |
Correct |
3 ms |
1024 KB |
Output is correct |
30 |
Correct |
3 ms |
896 KB |
Output is correct |
31 |
Correct |
4 ms |
1024 KB |
Output is correct |
32 |
Correct |
3 ms |
1024 KB |
Output is correct |
33 |
Correct |
15 ms |
3456 KB |
Output is correct |
34 |
Correct |
18 ms |
3448 KB |
Output is correct |
35 |
Correct |
39 ms |
3508 KB |
Output is correct |
36 |
Correct |
16 ms |
3968 KB |
Output is correct |
37 |
Correct |
18 ms |
3940 KB |
Output is correct |
38 |
Correct |
45 ms |
3848 KB |
Output is correct |
39 |
Correct |
29 ms |
4344 KB |
Output is correct |
40 |
Correct |
19 ms |
4352 KB |
Output is correct |
41 |
Correct |
67 ms |
4444 KB |
Output is correct |
42 |
Correct |
23 ms |
4864 KB |
Output is correct |
43 |
Correct |
24 ms |
4856 KB |
Output is correct |
44 |
Correct |
82 ms |
4860 KB |
Output is correct |
45 |
Correct |
27 ms |
5248 KB |
Output is correct |
46 |
Correct |
26 ms |
5240 KB |
Output is correct |
47 |
Correct |
88 ms |
5240 KB |
Output is correct |
48 |
Correct |
31 ms |
5752 KB |
Output is correct |
49 |
Correct |
36 ms |
5760 KB |
Output is correct |
50 |
Correct |
114 ms |
5752 KB |
Output is correct |
51 |
Correct |
36 ms |
6140 KB |
Output is correct |
52 |
Correct |
39 ms |
6136 KB |
Output is correct |
53 |
Correct |
145 ms |
6136 KB |
Output is correct |
54 |
Correct |
43 ms |
6648 KB |
Output is correct |
55 |
Correct |
49 ms |
6648 KB |
Output is correct |
56 |
Correct |
173 ms |
6776 KB |
Output is correct |
57 |
Correct |
45 ms |
7032 KB |
Output is correct |
58 |
Correct |
52 ms |
7032 KB |
Output is correct |
59 |
Correct |
203 ms |
7032 KB |
Output is correct |
60 |
Correct |
63 ms |
7672 KB |
Output is correct |
61 |
Correct |
54 ms |
7416 KB |
Output is correct |
62 |
Correct |
203 ms |
7528 KB |
Output is correct |
63 |
Correct |
165 ms |
7544 KB |
Output is correct |
64 |
Correct |
292 ms |
7544 KB |
Output is correct |
65 |
Correct |
251 ms |
7548 KB |
Output is correct |
66 |
Correct |
232 ms |
7544 KB |
Output is correct |
67 |
Correct |
183 ms |
7568 KB |
Output is correct |
68 |
Correct |
92 ms |
7544 KB |
Output is correct |
69 |
Correct |
93 ms |
7684 KB |
Output is correct |
70 |
Correct |
92 ms |
7472 KB |
Output is correct |
71 |
Correct |
76 ms |
7540 KB |
Output is correct |
72 |
Correct |
67 ms |
7544 KB |
Output is correct |
73 |
Correct |
97 ms |
7800 KB |
Output is correct |
74 |
Correct |
133 ms |
7868 KB |
Output is correct |
75 |
Correct |
182 ms |
7804 KB |
Output is correct |
76 |
Correct |
139 ms |
7800 KB |
Output is correct |
77 |
Correct |
160 ms |
7900 KB |
Output is correct |
78 |
Correct |
154 ms |
7800 KB |
Output is correct |
79 |
Correct |
111 ms |
7800 KB |
Output is correct |
80 |
Correct |
130 ms |
7800 KB |
Output is correct |
81 |
Correct |
143 ms |
7672 KB |
Output is correct |
82 |
Correct |
123 ms |
7800 KB |
Output is correct |
83 |
Correct |
149 ms |
7720 KB |
Output is correct |
84 |
Correct |
152 ms |
7672 KB |
Output is correct |
85 |
Correct |
198 ms |
7856 KB |
Output is correct |
86 |
Correct |
153 ms |
7672 KB |
Output is correct |
87 |
Correct |
176 ms |
7752 KB |
Output is correct |
88 |
Correct |
158 ms |
7800 KB |
Output is correct |
89 |
Correct |
180 ms |
7736 KB |
Output is correct |
90 |
Correct |
146 ms |
7780 KB |
Output is correct |
91 |
Correct |
184 ms |
7696 KB |
Output is correct |
92 |
Correct |
170 ms |
7672 KB |
Output is correct |