#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 mxtime;
int main() {
queue < pair<int,int> > bfs;
int n,sr,sc,er,ec;
double s;
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') continue;
visited[nr][nc] = true;
distBee[nr][nc] = distBee[curR][curC]+1;
mxtime = max(mxtime,distBee[nr][nc]);
bfs.push({nr,nc});
}
}
for (int i=mxtime;i>=0;i--) {
memset(visited,0,sizeof visited);
distBear[sr][sc] = i;
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]) return cout << i << endl,0;
}
cout << -1 << endl;
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:57:27: warning: 'ec' may be used uninitialized in this function [-Wmaybe-uninitialized]
57 | if (visited[er][ec]) return cout << i << endl,0;
| ~~~~~~~~~~~~~~^
mecho.cpp:57:27: warning: 'er' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Incorrect |
1 ms |
932 KB |
Output isn't correct |
5 |
Correct |
1 ms |
956 KB |
Output is correct |
6 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
7 |
Execution timed out |
1060 ms |
7076 KB |
Time limit exceeded |
8 |
Correct |
1 ms |
960 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
980 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Incorrect |
3 ms |
1340 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
14 |
Correct |
2 ms |
1236 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
956 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
1076 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1080 KB |
Output is correct |
22 |
Correct |
1 ms |
1080 KB |
Output is correct |
23 |
Correct |
2 ms |
1080 KB |
Output is correct |
24 |
Correct |
2 ms |
1108 KB |
Output is correct |
25 |
Correct |
2 ms |
1108 KB |
Output is correct |
26 |
Correct |
2 ms |
1108 KB |
Output is correct |
27 |
Correct |
2 ms |
1108 KB |
Output is correct |
28 |
Correct |
2 ms |
1212 KB |
Output is correct |
29 |
Correct |
2 ms |
1236 KB |
Output is correct |
30 |
Correct |
2 ms |
1236 KB |
Output is correct |
31 |
Correct |
2 ms |
1236 KB |
Output is correct |
32 |
Correct |
2 ms |
1236 KB |
Output is correct |
33 |
Correct |
15 ms |
2388 KB |
Output is correct |
34 |
Correct |
11 ms |
2372 KB |
Output is correct |
35 |
Correct |
293 ms |
4616 KB |
Output is correct |
36 |
Correct |
19 ms |
2644 KB |
Output is correct |
37 |
Correct |
16 ms |
2624 KB |
Output is correct |
38 |
Correct |
441 ms |
5268 KB |
Output is correct |
39 |
Correct |
22 ms |
2900 KB |
Output is correct |
40 |
Correct |
19 ms |
2924 KB |
Output is correct |
41 |
Correct |
623 ms |
5704 KB |
Output is correct |
42 |
Correct |
26 ms |
3156 KB |
Output is correct |
43 |
Correct |
21 ms |
3140 KB |
Output is correct |
44 |
Correct |
871 ms |
6288 KB |
Output is correct |
45 |
Correct |
32 ms |
3384 KB |
Output is correct |
46 |
Correct |
25 ms |
3380 KB |
Output is correct |
47 |
Execution timed out |
1086 ms |
6800 KB |
Time limit exceeded |
48 |
Correct |
34 ms |
3648 KB |
Output is correct |
49 |
Correct |
30 ms |
3568 KB |
Output is correct |
50 |
Execution timed out |
1085 ms |
7400 KB |
Time limit exceeded |
51 |
Correct |
38 ms |
3916 KB |
Output is correct |
52 |
Correct |
34 ms |
3904 KB |
Output is correct |
53 |
Execution timed out |
1087 ms |
7880 KB |
Time limit exceeded |
54 |
Correct |
44 ms |
4168 KB |
Output is correct |
55 |
Correct |
40 ms |
4176 KB |
Output is correct |
56 |
Execution timed out |
1082 ms |
8536 KB |
Time limit exceeded |
57 |
Correct |
49 ms |
4400 KB |
Output is correct |
58 |
Correct |
47 ms |
4428 KB |
Output is correct |
59 |
Execution timed out |
1088 ms |
9240 KB |
Time limit exceeded |
60 |
Correct |
55 ms |
4660 KB |
Output is correct |
61 |
Correct |
50 ms |
4684 KB |
Output is correct |
62 |
Execution timed out |
1085 ms |
9800 KB |
Time limit exceeded |
63 |
Execution timed out |
1082 ms |
7164 KB |
Time limit exceeded |
64 |
Execution timed out |
1090 ms |
7756 KB |
Time limit exceeded |
65 |
Execution timed out |
1086 ms |
7760 KB |
Time limit exceeded |
66 |
Execution timed out |
1089 ms |
7268 KB |
Time limit exceeded |
67 |
Execution timed out |
1095 ms |
7232 KB |
Time limit exceeded |
68 |
Correct |
152 ms |
9220 KB |
Output is correct |
69 |
Correct |
85 ms |
9308 KB |
Output is correct |
70 |
Correct |
80 ms |
9140 KB |
Output is correct |
71 |
Correct |
82 ms |
9040 KB |
Output is correct |
72 |
Incorrect |
58 ms |
5384 KB |
Output isn't correct |
73 |
Incorrect |
66 ms |
9924 KB |
Output isn't correct |
74 |
Correct |
278 ms |
9252 KB |
Output is correct |
75 |
Correct |
589 ms |
9808 KB |
Output is correct |
76 |
Correct |
499 ms |
9596 KB |
Output is correct |
77 |
Correct |
487 ms |
9660 KB |
Output is correct |
78 |
Execution timed out |
1034 ms |
7580 KB |
Time limit exceeded |
79 |
Correct |
163 ms |
6604 KB |
Output is correct |
80 |
Correct |
339 ms |
6772 KB |
Output is correct |
81 |
Correct |
744 ms |
7024 KB |
Output is correct |
82 |
Correct |
396 ms |
6704 KB |
Output is correct |
83 |
Execution timed out |
1079 ms |
7328 KB |
Time limit exceeded |
84 |
Correct |
528 ms |
7116 KB |
Output is correct |
85 |
Correct |
333 ms |
7216 KB |
Output is correct |
86 |
Correct |
754 ms |
7276 KB |
Output is correct |
87 |
Correct |
700 ms |
7216 KB |
Output is correct |
88 |
Correct |
981 ms |
7752 KB |
Output is correct |
89 |
Correct |
678 ms |
7500 KB |
Output is correct |
90 |
Execution timed out |
1085 ms |
7404 KB |
Time limit exceeded |
91 |
Correct |
854 ms |
7320 KB |
Output is correct |
92 |
Execution timed out |
1012 ms |
7564 KB |
Time limit exceeded |