# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
971388 |
2024-04-28T12:48:58 Z |
meatball |
Mecho (IOI09_mecho) |
C++14 |
|
145 ms |
6836 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
// https://oj.uz/problem/view/IOI09_mecho
const int MAX = 800;
char grid[MAX][MAX];
int n, s, dist[MAX][MAX],
dr[4] = {1, -1, 0, 0},
dc[4] = {0, 0, 1, -1};
pair<int, int> st, ed;
bool check(int mid) {
int trav[n][n];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
trav[i][j]=INT_MAX;
}
}
queue<pair<int, int>> q;
q.push(st);
//trav: 剩餘時間
trav[st.f][st.s]=mid*s;
while (!q.empty()) {
pair<int, int> p=q.front(); q.pop();
int r=p.f, c=p.s;
if (grid[r][c]=='D') {
return true;
}
for (int i=0; i<4; i++) {
int nr=r+dr[i], nc=c+dc[i];
if (nr>=0 && nr<n && nc>=0 && nc<n && grid[nr][nc]!='T' && trav[nr][nc]==INT_MAX){
trav[nr][nc]=trav[r][c]-1;
if (trav[nr][nc]>dist[nr][nc]) {
q.push({nr, nc});
}
}
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> s;
queue<pair<int, int>> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> grid[i][j];
dist[i][j] = 2e9;
if (grid[i][j] == 'H') {
q.push({i, j});
dist[i][j] = 0;
} else if (grid[i][j] == 'M') {
st = {i, j};
} else if (grid[i][j] == 'D') {
ed = {i, j};
}
}
}
while (!q.empty()) {
auto p = q.front(); q.pop();
int r = p.f, c = p.s;
for (int i = 0; i < 4; i++) {
int r1 = r + dr[i], c1 = c + dc[i];
if (r1 >= 0 && r1 < n && c1 >= 0 && c1 < n
&& dist[r][c] + 1 < dist[r1][c1] &&
grid[r1][c1] != 'T' && grid[r1][c1] != 'D') {
dist[r1][c1] = dist[r][c] + 1;
q.push({r1, c1});
}
}
}
int low = 0, high = dist[st.f][st.s] - 1;
while (low < high) {
int mid = (low + high + 1) / 2;
if (check(mid)) {
low = mid;
} else {
high = mid - 1;
}
}
if (check(low)) cout << low << '\n';
else cout << -1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
65 ms |
6068 KB |
Output isn't correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
25 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
2676 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
33 |
Incorrect |
4 ms |
3420 KB |
Output isn't correct |
34 |
Incorrect |
10 ms |
3416 KB |
Output isn't correct |
35 |
Incorrect |
12 ms |
3416 KB |
Output isn't correct |
36 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
37 |
Incorrect |
13 ms |
3928 KB |
Output isn't correct |
38 |
Incorrect |
18 ms |
3672 KB |
Output isn't correct |
39 |
Incorrect |
6 ms |
3932 KB |
Output isn't correct |
40 |
Incorrect |
16 ms |
3980 KB |
Output isn't correct |
41 |
Incorrect |
20 ms |
3932 KB |
Output isn't correct |
42 |
Incorrect |
7 ms |
4188 KB |
Output isn't correct |
43 |
Incorrect |
21 ms |
4188 KB |
Output isn't correct |
44 |
Incorrect |
25 ms |
4440 KB |
Output isn't correct |
45 |
Incorrect |
9 ms |
4444 KB |
Output isn't correct |
46 |
Incorrect |
27 ms |
4516 KB |
Output isn't correct |
47 |
Incorrect |
33 ms |
4444 KB |
Output isn't correct |
48 |
Incorrect |
11 ms |
4696 KB |
Output isn't correct |
49 |
Incorrect |
35 ms |
4700 KB |
Output isn't correct |
50 |
Incorrect |
39 ms |
4700 KB |
Output isn't correct |
51 |
Incorrect |
12 ms |
4952 KB |
Output isn't correct |
52 |
Incorrect |
39 ms |
4988 KB |
Output isn't correct |
53 |
Incorrect |
51 ms |
4956 KB |
Output isn't correct |
54 |
Incorrect |
14 ms |
5212 KB |
Output isn't correct |
55 |
Incorrect |
42 ms |
5468 KB |
Output isn't correct |
56 |
Incorrect |
53 ms |
5468 KB |
Output isn't correct |
57 |
Incorrect |
17 ms |
5724 KB |
Output isn't correct |
58 |
Incorrect |
48 ms |
5760 KB |
Output isn't correct |
59 |
Incorrect |
76 ms |
5948 KB |
Output isn't correct |
60 |
Incorrect |
19 ms |
6492 KB |
Output isn't correct |
61 |
Incorrect |
54 ms |
6488 KB |
Output isn't correct |
62 |
Incorrect |
70 ms |
6488 KB |
Output isn't correct |
63 |
Incorrect |
24 ms |
6224 KB |
Output isn't correct |
64 |
Incorrect |
145 ms |
6440 KB |
Output isn't correct |
65 |
Incorrect |
39 ms |
6488 KB |
Output isn't correct |
66 |
Incorrect |
31 ms |
6224 KB |
Output isn't correct |
67 |
Correct |
24 ms |
6228 KB |
Output is correct |
68 |
Incorrect |
54 ms |
6492 KB |
Output isn't correct |
69 |
Incorrect |
83 ms |
6684 KB |
Output isn't correct |
70 |
Incorrect |
40 ms |
6636 KB |
Output isn't correct |
71 |
Incorrect |
29 ms |
6484 KB |
Output isn't correct |
72 |
Incorrect |
96 ms |
6516 KB |
Output isn't correct |
73 |
Incorrect |
21 ms |
6748 KB |
Output isn't correct |
74 |
Incorrect |
103 ms |
6744 KB |
Output isn't correct |
75 |
Incorrect |
40 ms |
6736 KB |
Output isn't correct |
76 |
Incorrect |
37 ms |
6540 KB |
Output isn't correct |
77 |
Incorrect |
54 ms |
6740 KB |
Output isn't correct |
78 |
Correct |
49 ms |
6544 KB |
Output is correct |
79 |
Incorrect |
106 ms |
6836 KB |
Output isn't correct |
80 |
Incorrect |
44 ms |
6492 KB |
Output isn't correct |
81 |
Incorrect |
43 ms |
6696 KB |
Output isn't correct |
82 |
Incorrect |
57 ms |
6484 KB |
Output isn't correct |
83 |
Incorrect |
47 ms |
6484 KB |
Output isn't correct |
84 |
Incorrect |
93 ms |
6536 KB |
Output isn't correct |
85 |
Incorrect |
44 ms |
6628 KB |
Output isn't correct |
86 |
Incorrect |
47 ms |
6492 KB |
Output isn't correct |
87 |
Incorrect |
72 ms |
6484 KB |
Output isn't correct |
88 |
Incorrect |
54 ms |
6484 KB |
Output isn't correct |
89 |
Incorrect |
92 ms |
6488 KB |
Output isn't correct |
90 |
Incorrect |
62 ms |
6492 KB |
Output isn't correct |
91 |
Incorrect |
75 ms |
6648 KB |
Output isn't correct |
92 |
Incorrect |
56 ms |
6676 KB |
Output isn't correct |