#include <bits/stdc++.h>
using namespace std;
bool visited[805][805];
int distBee[805][805];
double distBear[805][805];
char g[805][805];
int dr[] = {-1,0,1,0};
int dc[] = {0,1,0,-1};
int n,sr,sc,er,ec,mxtime;
double s;
bool success;
bool possible(double t) {
memset(visited,0,sizeof visited);
queue < pair<int,int> > bfs;
distBear[sr][sc] = t;
bfs.push({sr,sc});
while (!bfs.empty()) {
int curR = bfs.front().first;
int curC = bfs.front().second;
bfs.pop();
for (int i=0;i<4;i++) {
int nr = curR + dr[i];
int nc = curC + dc[i];
if (nr<1||nr>n||nc<1||nc>n||visited[nr][nc]||g[nr][nc]=='T'||distBear[curR][curC]+(double)1/s>=(double)distBee[nr][nc]) continue;
visited[nr][nc] = true;
distBear[nr][nc] = distBear[curR][curC]+1/s;
bfs.push({nr,nc});
}
}
if (visited[er][ec]) {
success = true;
return true;
}
return false;
}
int main() {
queue < pair<int,int> > bfs;
cin >> n >> s;
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
cin >> g[i][j];
if (g[i][j]=='M') sr = i,sc = j;
else if (g[i][j]=='D') er = i,ec = j;
else if (g[i][j]=='H') {
visited[i][j] = true;
bfs.push({i,j});
}
}
}
while (!bfs.empty()) {
int curR = bfs.front().first;
int curC = bfs.front().second;
bfs.pop();
for (int i=0;i<4;i++) {
int nr = curR + dr[i];
int nc = curC + dc[i];
if (nr<1||nr>n||nc<1||nc>n||visited[nr][nc]||g[nr][nc]=='T'||g[nr][nc]=='D') continue;
visited[nr][nc] = true;
distBee[nr][nc] = distBee[curR][curC]+1;
if (g[nr][nc]=='M') continue;
bfs.push({nr,nc});
}
}
int lo = 0,hi = distBee[sr][sc]-1;
while (lo<hi) {
int mid = (lo+hi+1)/2;
if (possible((double)mid)) lo = mid;
else hi = mid-1;
}
if (!possible(0)) cout << -1 << endl;
else cout << lo << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
7 |
Incorrect |
117 ms |
9192 KB |
Output isn't correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1364 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
14 |
Correct |
1 ms |
1236 KB |
Output is correct |
15 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
1352 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
1236 KB |
Output isn't correct |
26 |
Incorrect |
2 ms |
1364 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
1492 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
1364 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
1492 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
1364 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
1492 KB |
Output isn't correct |
33 |
Incorrect |
20 ms |
3156 KB |
Output isn't correct |
34 |
Incorrect |
28 ms |
4284 KB |
Output isn't correct |
35 |
Incorrect |
25 ms |
4512 KB |
Output isn't correct |
36 |
Incorrect |
28 ms |
3540 KB |
Output isn't correct |
37 |
Incorrect |
38 ms |
4872 KB |
Output isn't correct |
38 |
Incorrect |
32 ms |
4904 KB |
Output isn't correct |
39 |
Incorrect |
36 ms |
3980 KB |
Output isn't correct |
40 |
Incorrect |
51 ms |
5392 KB |
Output isn't correct |
41 |
Incorrect |
42 ms |
5524 KB |
Output isn't correct |
42 |
Incorrect |
46 ms |
4172 KB |
Output isn't correct |
43 |
Incorrect |
55 ms |
5956 KB |
Output isn't correct |
44 |
Incorrect |
62 ms |
6044 KB |
Output isn't correct |
45 |
Incorrect |
55 ms |
4452 KB |
Output isn't correct |
46 |
Incorrect |
70 ms |
6436 KB |
Output isn't correct |
47 |
Incorrect |
72 ms |
6488 KB |
Output isn't correct |
48 |
Incorrect |
65 ms |
4812 KB |
Output isn't correct |
49 |
Incorrect |
87 ms |
6948 KB |
Output isn't correct |
50 |
Incorrect |
80 ms |
6988 KB |
Output isn't correct |
51 |
Incorrect |
73 ms |
5120 KB |
Output isn't correct |
52 |
Incorrect |
102 ms |
7352 KB |
Output isn't correct |
53 |
Incorrect |
100 ms |
7560 KB |
Output isn't correct |
54 |
Incorrect |
89 ms |
5408 KB |
Output isn't correct |
55 |
Incorrect |
113 ms |
7832 KB |
Output isn't correct |
56 |
Incorrect |
110 ms |
8072 KB |
Output isn't correct |
57 |
Incorrect |
102 ms |
5788 KB |
Output isn't correct |
58 |
Incorrect |
139 ms |
8148 KB |
Output isn't correct |
59 |
Incorrect |
142 ms |
8480 KB |
Output isn't correct |
60 |
Incorrect |
115 ms |
6072 KB |
Output isn't correct |
61 |
Incorrect |
154 ms |
8644 KB |
Output isn't correct |
62 |
Incorrect |
164 ms |
9048 KB |
Output isn't correct |
63 |
Incorrect |
126 ms |
8972 KB |
Output isn't correct |
64 |
Incorrect |
235 ms |
9108 KB |
Output isn't correct |
65 |
Incorrect |
216 ms |
9100 KB |
Output isn't correct |
66 |
Incorrect |
189 ms |
9112 KB |
Output isn't correct |
67 |
Correct |
140 ms |
8820 KB |
Output is correct |
68 |
Incorrect |
75 ms |
8668 KB |
Output isn't correct |
69 |
Incorrect |
82 ms |
8752 KB |
Output isn't correct |
70 |
Incorrect |
72 ms |
8524 KB |
Output isn't correct |
71 |
Incorrect |
69 ms |
8528 KB |
Output isn't correct |
72 |
Incorrect |
86 ms |
8908 KB |
Output isn't correct |
73 |
Incorrect |
61 ms |
9336 KB |
Output isn't correct |
74 |
Incorrect |
127 ms |
9292 KB |
Output isn't correct |
75 |
Incorrect |
99 ms |
9380 KB |
Output isn't correct |
76 |
Incorrect |
95 ms |
9220 KB |
Output isn't correct |
77 |
Incorrect |
101 ms |
9276 KB |
Output isn't correct |
78 |
Correct |
97 ms |
6744 KB |
Output is correct |
79 |
Incorrect |
133 ms |
9236 KB |
Output isn't correct |
80 |
Incorrect |
103 ms |
6724 KB |
Output isn't correct |
81 |
Incorrect |
93 ms |
6656 KB |
Output isn't correct |
82 |
Incorrect |
98 ms |
6852 KB |
Output isn't correct |
83 |
Incorrect |
100 ms |
6748 KB |
Output isn't correct |
84 |
Incorrect |
146 ms |
9356 KB |
Output isn't correct |
85 |
Incorrect |
107 ms |
6928 KB |
Output isn't correct |
86 |
Incorrect |
102 ms |
6800 KB |
Output isn't correct |
87 |
Incorrect |
107 ms |
7116 KB |
Output isn't correct |
88 |
Incorrect |
97 ms |
6960 KB |
Output isn't correct |
89 |
Incorrect |
166 ms |
9232 KB |
Output isn't correct |
90 |
Incorrect |
115 ms |
8320 KB |
Output isn't correct |
91 |
Incorrect |
117 ms |
9212 KB |
Output isn't correct |
92 |
Incorrect |
103 ms |
7116 KB |
Output isn't correct |