# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
518468 |
2022-01-23T21:20:34 Z |
Alex_tz307 |
Mecho (IOI09_mecho) |
C++17 |
|
188 ms |
6232 KB |
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
void testCase() {
int n, s;
cin >> n >> s;
vector<string> a(n);
queue<pair<int, int>> q;
vector<vector<int>> bee(n, vector<int>(n, INF));
int istart = -1, jstart = -1, istop = -1, jstop = -1;
for (int i = 0; i < n; ++i) {
cin >> a[i];
for (int j = 0; j < n; ++j) {
if (a[i][j] == 'H') {
bee[i][j] = 1;
q.emplace(i, j);
} else if (a[i][j] == 'M') {
istart = i, jstart = j;
} else if (a[i][j] == 'D') {
istop = i, jstop = j;
}
}
}
const int di[] = {-1, 0, 1, 0}, dj[] = {0, 1, 0, -1};
auto valid = [&](const int &i, const int &j) -> bool {
return 0 <= min(i, j) && max(i, j) < n && a[i][j] != 'T' && a[i][j] != 'H';
};
while (!q.empty()) {
int i, j;
tie(i, j) = q.front();
q.pop();
for (int k = 0; k < 4; ++k) {
int iv = i + di[k], jv = j + dj[k];
if (valid(iv, jv) && a[iv][jv] != 'D' && bee[iv][jv] == INF) {
bee[iv][jv] = bee[i][j] + 1;
q.emplace(iv, jv);
}
}
}
auto checkDistance = [&](const int &m, const int &b) -> bool {
return m / s < b;
};
auto check = [&](const int &t) -> bool {
vector<vector<int>> dp(n, vector<int>(n, INF));
queue<pair<int, int>> q;
dp[istart][jstart] = t;
q.emplace(istart, jstart);
while (!q.empty()) {
int i, j;
tie(i, j) = q.front();
q.pop();
for (int k = 0; k < 4; ++k) {
int iv = i + di[k], jv = j + dj[k];
if (valid(iv, jv) && dp[iv][jv] == INF && checkDistance(dp[i][j] + 1, bee[iv][jv] - t)) {
dp[iv][jv] = dp[i][j] + 1;
q.emplace(iv, jv);
}
}
}
if (dp[istop][jstop] == INF) {
return false;
}
return true;
};
int l = 0, r = bee[istart][jstart] - 1, ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Incorrect |
88 ms |
6084 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
26 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
28 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
1436 KB |
Output isn't correct |
34 |
Incorrect |
6 ms |
1468 KB |
Output isn't correct |
35 |
Incorrect |
30 ms |
1416 KB |
Output isn't correct |
36 |
Incorrect |
7 ms |
1740 KB |
Output isn't correct |
37 |
Incorrect |
8 ms |
1740 KB |
Output isn't correct |
38 |
Incorrect |
23 ms |
1784 KB |
Output isn't correct |
39 |
Incorrect |
8 ms |
2204 KB |
Output isn't correct |
40 |
Incorrect |
9 ms |
2148 KB |
Output isn't correct |
41 |
Incorrect |
36 ms |
2160 KB |
Output isn't correct |
42 |
Incorrect |
10 ms |
2580 KB |
Output isn't correct |
43 |
Incorrect |
12 ms |
2576 KB |
Output isn't correct |
44 |
Incorrect |
58 ms |
2584 KB |
Output isn't correct |
45 |
Incorrect |
15 ms |
3108 KB |
Output isn't correct |
46 |
Incorrect |
20 ms |
3084 KB |
Output isn't correct |
47 |
Incorrect |
53 ms |
3020 KB |
Output isn't correct |
48 |
Incorrect |
16 ms |
3636 KB |
Output isn't correct |
49 |
Incorrect |
16 ms |
3628 KB |
Output isn't correct |
50 |
Incorrect |
65 ms |
3560 KB |
Output isn't correct |
51 |
Incorrect |
27 ms |
4124 KB |
Output isn't correct |
52 |
Incorrect |
31 ms |
4128 KB |
Output isn't correct |
53 |
Incorrect |
70 ms |
4124 KB |
Output isn't correct |
54 |
Incorrect |
21 ms |
4780 KB |
Output isn't correct |
55 |
Incorrect |
30 ms |
4764 KB |
Output isn't correct |
56 |
Incorrect |
97 ms |
4748 KB |
Output isn't correct |
57 |
Incorrect |
40 ms |
5428 KB |
Output isn't correct |
58 |
Incorrect |
28 ms |
5436 KB |
Output isn't correct |
59 |
Incorrect |
109 ms |
5364 KB |
Output isn't correct |
60 |
Incorrect |
28 ms |
6128 KB |
Output isn't correct |
61 |
Incorrect |
29 ms |
6116 KB |
Output isn't correct |
62 |
Incorrect |
114 ms |
6072 KB |
Output isn't correct |
63 |
Correct |
121 ms |
6068 KB |
Output is correct |
64 |
Correct |
188 ms |
6104 KB |
Output is correct |
65 |
Incorrect |
155 ms |
6156 KB |
Output isn't correct |
66 |
Incorrect |
140 ms |
6076 KB |
Output isn't correct |
67 |
Correct |
110 ms |
6088 KB |
Output is correct |
68 |
Incorrect |
48 ms |
6080 KB |
Output isn't correct |
69 |
Correct |
48 ms |
6212 KB |
Output is correct |
70 |
Correct |
40 ms |
6084 KB |
Output is correct |
71 |
Correct |
42 ms |
6100 KB |
Output is correct |
72 |
Incorrect |
34 ms |
6088 KB |
Output isn't correct |
73 |
Incorrect |
34 ms |
6092 KB |
Output isn't correct |
74 |
Correct |
60 ms |
6096 KB |
Output is correct |
75 |
Incorrect |
73 ms |
6132 KB |
Output isn't correct |
76 |
Incorrect |
66 ms |
6232 KB |
Output isn't correct |
77 |
Incorrect |
71 ms |
6124 KB |
Output isn't correct |
78 |
Correct |
71 ms |
6104 KB |
Output is correct |
79 |
Correct |
57 ms |
6224 KB |
Output is correct |
80 |
Incorrect |
62 ms |
6112 KB |
Output isn't correct |
81 |
Incorrect |
69 ms |
6120 KB |
Output isn't correct |
82 |
Incorrect |
82 ms |
6164 KB |
Output isn't correct |
83 |
Incorrect |
79 ms |
6120 KB |
Output isn't correct |
84 |
Correct |
64 ms |
6104 KB |
Output is correct |
85 |
Incorrect |
67 ms |
6088 KB |
Output isn't correct |
86 |
Incorrect |
81 ms |
6116 KB |
Output isn't correct |
87 |
Incorrect |
85 ms |
6112 KB |
Output isn't correct |
88 |
Incorrect |
79 ms |
6104 KB |
Output isn't correct |
89 |
Correct |
76 ms |
6092 KB |
Output is correct |
90 |
Correct |
84 ms |
6084 KB |
Output is correct |
91 |
Correct |
82 ms |
6096 KB |
Output is correct |
92 |
Incorrect |
72 ms |
6176 KB |
Output isn't correct |