#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
int movex[4] = {-1, 0, 1, 0};
int movey[4] = {0, 1, 0, -1};
char maps[805][805];
int beeStep[805][805], meStep[805][805], n, Mx, My, s, Dx, Dy;
queue <pair <int, int> > bee, me;
bool check(int x, int y) {
if(x >= 0 && x < n && y >= 0 && y < n) return true;
return false;
}
bool can(int mid) {
memset(meStep, -1, sizeof(meStep));
me.push(mp(Mx * 1000 + My, mid));
while(!me.empty()) {
int curx = me.front().F / 1000;
int cury = me.front().F % 1000;
int curstep = me.front().S;
me.pop();
if(meStep[curx][cury] != -1) continue;
meStep[curx][cury] = curstep;
for(int i = 0; i < 4; i++) {
for(int i1 = 1; i1 <= s; i1++) {
int movexx = movex[i] * i1 + curx;
int moveyy = movey[i] * i1 + cury;
if(check(movexx, moveyy) && maps[movexx][moveyy] != 'T' && meStep[movexx][moveyy] == -1) {
if(beeStep[movexx][moveyy] != -1 && beeStep[movexx][moveyy] <= curstep) break;
me.push(mp(movexx * 1000 + moveyy, curstep + 1));
}
else break;
}
}
}
//cout << meStep[Dx][Dy] << " " << beeStep[Dx][Dy] << "\n";
if(beeStep[Dx][Dy] == -1) beeStep[Dx][Dy] = 1e9;
if(meStep[Dx][Dy] == -1) return false;
return meStep[Dx][Dy] < beeStep[Dx][Dy];
}
int main() {
int i, j, l, r;
scanf("%d%d", &n, &s);
for(i = 0; i < n; i++) {
scanf("%s", maps[i]);
for(j = 0; j < n; j++) {
if(maps[i][j] == 'H')
bee.push(mp(i * 1000 + j, 0));
if(maps[i][j] == 'M') {
Mx = i; My = j;
}
if(maps[i][j] == 'D') {
Dx = i; Dy = j;
}
}
}
memset(beeStep, -1, sizeof(beeStep));
while(!bee.empty()) {
int curx = bee.front().F / 1000;
int cury = bee.front().F % 1000;
int curstep = bee.front().S;
bee.pop();
if(beeStep[curx][cury] != -1) continue;
beeStep[curx][cury] = curstep;
for(int i = 0; i < 4; i++) {
int movexx = movex[i] + curx;
int moveyy = movey[i] + cury;
if(check(movexx, moveyy) && maps[movexx][moveyy] != 'T' && beeStep[movexx][moveyy] == -1)
bee.push(mp(movexx * 1000 + moveyy, curstep + 1));
}
}
l = 0; r = 1e9;
while(l != r) {
int mid = (l + r + 1) / 2;
if(can(mid)) l = mid ;
else r = mid - 1;
}
printf("%d\n", l);
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &s);
~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", maps[i]);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
5376 KB |
Output is correct |
2 |
Incorrect |
9 ms |
5376 KB |
Output isn't correct |
3 |
Correct |
10 ms |
5376 KB |
Output is correct |
4 |
Incorrect |
11 ms |
5376 KB |
Output isn't correct |
5 |
Correct |
9 ms |
5376 KB |
Output is correct |
6 |
Incorrect |
11 ms |
5376 KB |
Output isn't correct |
7 |
Execution timed out |
1064 ms |
16732 KB |
Time limit exceeded |
8 |
Incorrect |
9 ms |
5376 KB |
Output isn't correct |
9 |
Correct |
10 ms |
5376 KB |
Output is correct |
10 |
Correct |
10 ms |
5376 KB |
Output is correct |
11 |
Correct |
10 ms |
5376 KB |
Output is correct |
12 |
Incorrect |
10 ms |
5504 KB |
Output isn't correct |
13 |
Incorrect |
12 ms |
5504 KB |
Output isn't correct |
14 |
Incorrect |
11 ms |
5504 KB |
Output isn't correct |
15 |
Correct |
11 ms |
5376 KB |
Output is correct |
16 |
Correct |
10 ms |
5376 KB |
Output is correct |
17 |
Correct |
11 ms |
5504 KB |
Output is correct |
18 |
Correct |
10 ms |
5376 KB |
Output is correct |
19 |
Correct |
11 ms |
5504 KB |
Output is correct |
20 |
Correct |
10 ms |
5376 KB |
Output is correct |
21 |
Correct |
11 ms |
5504 KB |
Output is correct |
22 |
Correct |
10 ms |
5504 KB |
Output is correct |
23 |
Correct |
11 ms |
5504 KB |
Output is correct |
24 |
Correct |
10 ms |
5376 KB |
Output is correct |
25 |
Correct |
13 ms |
5376 KB |
Output is correct |
26 |
Correct |
13 ms |
5504 KB |
Output is correct |
27 |
Correct |
12 ms |
5504 KB |
Output is correct |
28 |
Correct |
12 ms |
5504 KB |
Output is correct |
29 |
Correct |
10 ms |
5504 KB |
Output is correct |
30 |
Correct |
11 ms |
5504 KB |
Output is correct |
31 |
Correct |
10 ms |
5504 KB |
Output is correct |
32 |
Correct |
11 ms |
5504 KB |
Output is correct |
33 |
Correct |
15 ms |
5760 KB |
Output is correct |
34 |
Correct |
134 ms |
6264 KB |
Output is correct |
35 |
Runtime error |
560 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
36 |
Correct |
14 ms |
5760 KB |
Output is correct |
37 |
Correct |
57 ms |
6400 KB |
Output is correct |
38 |
Runtime error |
336 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Correct |
16 ms |
5760 KB |
Output is correct |
40 |
Correct |
141 ms |
6664 KB |
Output is correct |
41 |
Runtime error |
407 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
42 |
Correct |
14 ms |
5760 KB |
Output is correct |
43 |
Correct |
35 ms |
6784 KB |
Output is correct |
44 |
Runtime error |
352 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
45 |
Correct |
16 ms |
5888 KB |
Output is correct |
46 |
Correct |
173 ms |
7168 KB |
Output is correct |
47 |
Runtime error |
258 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
48 |
Correct |
19 ms |
5888 KB |
Output is correct |
49 |
Correct |
354 ms |
7500 KB |
Output is correct |
50 |
Runtime error |
316 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
51 |
Correct |
25 ms |
5888 KB |
Output is correct |
52 |
Correct |
452 ms |
7820 KB |
Output is correct |
53 |
Runtime error |
168 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
54 |
Correct |
24 ms |
6016 KB |
Output is correct |
55 |
Correct |
804 ms |
8088 KB |
Output is correct |
56 |
Runtime error |
171 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
57 |
Correct |
21 ms |
6076 KB |
Output is correct |
58 |
Correct |
242 ms |
8572 KB |
Output is correct |
59 |
Runtime error |
173 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
60 |
Correct |
23 ms |
5996 KB |
Output is correct |
61 |
Correct |
442 ms |
8804 KB |
Output is correct |
62 |
Runtime error |
199 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
63 |
Correct |
112 ms |
6096 KB |
Output is correct |
64 |
Incorrect |
246 ms |
6136 KB |
Output isn't correct |
65 |
Incorrect |
194 ms |
6016 KB |
Output isn't correct |
66 |
Incorrect |
157 ms |
6008 KB |
Output isn't correct |
67 |
Incorrect |
172 ms |
6136 KB |
Output isn't correct |
68 |
Correct |
35 ms |
6136 KB |
Output is correct |
69 |
Incorrect |
44 ms |
6136 KB |
Output isn't correct |
70 |
Incorrect |
35 ms |
6008 KB |
Output isn't correct |
71 |
Incorrect |
38 ms |
6144 KB |
Output isn't correct |
72 |
Incorrect |
45 ms |
6136 KB |
Output isn't correct |
73 |
Incorrect |
208 ms |
6600 KB |
Output isn't correct |
74 |
Runtime error |
250 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
75 |
Incorrect |
521 ms |
6728 KB |
Output isn't correct |
76 |
Incorrect |
384 ms |
6596 KB |
Output isn't correct |
77 |
Execution timed out |
1070 ms |
7812 KB |
Time limit exceeded |
78 |
Incorrect |
990 ms |
7248 KB |
Output isn't correct |
79 |
Runtime error |
248 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
80 |
Incorrect |
667 ms |
6972 KB |
Output isn't correct |
81 |
Incorrect |
606 ms |
6572 KB |
Output isn't correct |
82 |
Incorrect |
959 ms |
8888 KB |
Output isn't correct |
83 |
Correct |
848 ms |
7012 KB |
Output is correct |
84 |
Runtime error |
336 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
85 |
Execution timed out |
1080 ms |
9144 KB |
Time limit exceeded |
86 |
Execution timed out |
1060 ms |
7668 KB |
Time limit exceeded |
87 |
Execution timed out |
1079 ms |
14196 KB |
Time limit exceeded |
88 |
Execution timed out |
1068 ms |
9444 KB |
Time limit exceeded |
89 |
Runtime error |
219 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
90 |
Execution timed out |
1046 ms |
15392 KB |
Time limit exceeded |
91 |
Execution timed out |
1078 ms |
30828 KB |
Time limit exceeded |
92 |
Execution timed out |
1076 ms |
11608 KB |
Time limit exceeded |