# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
518460 |
2022-01-23T21:02:18 Z |
Alex_tz307 |
Mecho (IOI09_mecho) |
C++17 |
|
164 ms |
6236 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 + 1, vector<int>(n + 1, 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] = 0;
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 + 1, vector<int>(n + 1, 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 = -2;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans + 1 << '\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 |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Incorrect |
93 ms |
6096 KB |
Output isn't correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 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 |
0 ms |
204 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
23 |
Incorrect |
1 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 |
1 ms |
332 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
344 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 |
1488 KB |
Output isn't correct |
34 |
Incorrect |
6 ms |
1440 KB |
Output isn't correct |
35 |
Incorrect |
19 ms |
1452 KB |
Output isn't correct |
36 |
Incorrect |
8 ms |
1740 KB |
Output isn't correct |
37 |
Incorrect |
9 ms |
1740 KB |
Output isn't correct |
38 |
Incorrect |
26 ms |
1784 KB |
Output isn't correct |
39 |
Incorrect |
10 ms |
2156 KB |
Output isn't correct |
40 |
Incorrect |
12 ms |
2208 KB |
Output isn't correct |
41 |
Incorrect |
34 ms |
2156 KB |
Output isn't correct |
42 |
Incorrect |
11 ms |
2636 KB |
Output isn't correct |
43 |
Incorrect |
11 ms |
2584 KB |
Output isn't correct |
44 |
Incorrect |
40 ms |
2588 KB |
Output isn't correct |
45 |
Incorrect |
13 ms |
3064 KB |
Output isn't correct |
46 |
Incorrect |
14 ms |
3076 KB |
Output isn't correct |
47 |
Incorrect |
53 ms |
3040 KB |
Output isn't correct |
48 |
Incorrect |
15 ms |
3580 KB |
Output isn't correct |
49 |
Incorrect |
18 ms |
3600 KB |
Output isn't correct |
50 |
Incorrect |
64 ms |
3584 KB |
Output isn't correct |
51 |
Incorrect |
19 ms |
4216 KB |
Output isn't correct |
52 |
Incorrect |
20 ms |
4156 KB |
Output isn't correct |
53 |
Incorrect |
68 ms |
4148 KB |
Output isn't correct |
54 |
Incorrect |
23 ms |
4752 KB |
Output isn't correct |
55 |
Incorrect |
30 ms |
4792 KB |
Output isn't correct |
56 |
Incorrect |
113 ms |
4724 KB |
Output isn't correct |
57 |
Incorrect |
25 ms |
5452 KB |
Output isn't correct |
58 |
Incorrect |
26 ms |
5444 KB |
Output isn't correct |
59 |
Incorrect |
94 ms |
5424 KB |
Output isn't correct |
60 |
Incorrect |
29 ms |
6120 KB |
Output isn't correct |
61 |
Incorrect |
30 ms |
6120 KB |
Output isn't correct |
62 |
Incorrect |
121 ms |
6092 KB |
Output isn't correct |
63 |
Incorrect |
112 ms |
6160 KB |
Output isn't correct |
64 |
Correct |
164 ms |
6084 KB |
Output is correct |
65 |
Incorrect |
142 ms |
6080 KB |
Output isn't correct |
66 |
Incorrect |
159 ms |
6076 KB |
Output isn't correct |
67 |
Correct |
121 ms |
6160 KB |
Output is correct |
68 |
Incorrect |
48 ms |
6128 KB |
Output isn't correct |
69 |
Correct |
38 ms |
6084 KB |
Output is correct |
70 |
Correct |
42 ms |
6088 KB |
Output is correct |
71 |
Correct |
44 ms |
6084 KB |
Output is correct |
72 |
Incorrect |
39 ms |
6100 KB |
Output isn't correct |
73 |
Incorrect |
33 ms |
6148 KB |
Output isn't correct |
74 |
Correct |
65 ms |
6132 KB |
Output is correct |
75 |
Incorrect |
61 ms |
6196 KB |
Output isn't correct |
76 |
Incorrect |
62 ms |
6132 KB |
Output isn't correct |
77 |
Incorrect |
67 ms |
6152 KB |
Output isn't correct |
78 |
Correct |
76 ms |
6100 KB |
Output is correct |
79 |
Correct |
55 ms |
6116 KB |
Output is correct |
80 |
Incorrect |
63 ms |
6112 KB |
Output isn't correct |
81 |
Incorrect |
69 ms |
6116 KB |
Output isn't correct |
82 |
Incorrect |
57 ms |
6108 KB |
Output isn't correct |
83 |
Incorrect |
78 ms |
6088 KB |
Output isn't correct |
84 |
Correct |
78 ms |
6236 KB |
Output is correct |
85 |
Incorrect |
66 ms |
6084 KB |
Output isn't correct |
86 |
Correct |
79 ms |
6104 KB |
Output is correct |
87 |
Incorrect |
73 ms |
6112 KB |
Output isn't correct |
88 |
Incorrect |
78 ms |
6108 KB |
Output isn't correct |
89 |
Correct |
85 ms |
6112 KB |
Output is correct |
90 |
Correct |
96 ms |
6080 KB |
Output is correct |
91 |
Correct |
96 ms |
6088 KB |
Output is correct |
92 |
Incorrect |
81 ms |
6112 KB |
Output isn't correct |