# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
491058 |
2021-11-30T06:08:17 Z |
sberens |
Mecho (IOI09_mecho) |
C++17 |
|
565 ms |
6288 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename K> using hset = gp_hash_table<K, null_type>;
template<typename K, typename V> using hmap = gp_hash_table<K, V>;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define smax(x, y) (x = max(x, y))
#define smin(x, y) (x = min(x, y))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
using ll = long long;
using ld = long double;
template<typename T>
using vv = vector<vector<T>>;
using vi = vector<int>;
using ii = array<int, 2>;
using vii = vector<ii>;
using vvi = vv<int>;
using vll = vector<ll>;
using l2 = array<ll, 2>;
using vl2 = vector<l2>;
using vvll = vv<ll>;
template<typename T>
using minq = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using maxq = priority_queue<T>;
const ll M = 1000000007;
const ll infll = M * M;
template<typename IN>
IN discrete_binary_search(function<bool(IN)> predicate, IN low = 0, IN high = numeric_limits<IN>::max()) {
while (low < high) {
IN middle = low + (high - low) / 2; // todo std::midpoint in cpp 2020
if (predicate(middle))
high = middle;
else low = middle + 1;
}
return low;
}
vii dirs{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
vii adjc(int x, int y) {
vii res;
for (auto [dx, dy] : dirs)
res.pb({x + dx, y + dy});
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, s;
cin >> n >> s;
vv<char> g(n, vector<char>(n));
int mr, mc, dr, dc;
vii hives;
F0R(i, n) {
F0R(j, n) {
char x;
cin >> x;
g[i][j] = x;
if (x == 'M') {
mr = i;
mc = j;
} else if (x == 'H') {
hives.pb({i, j});
} else if (x == 'D') {
dr = i;
dc = j;
}
}
}
vvi beetime(n, vi(n, M));
queue<ii> bees;
for (auto [r, c] : hives) {
bees.push({r, c});
beetime[r][c] = 0;
}
F0R(t, n * n) {
queue<ii> nextbees;
while (!bees.empty()) {
assert(bees.size() < n * n);
auto [r, c] = bees.front(); bees.pop();
for (auto [nr, nc] : adjc(r, c)) {
if (0 <= nr && nr < n && 0 <= nc && nc < n && beetime[nr][nc] == M && (g[nr][nc] == 'G' || g[nr][nc] == 'M')) {
nextbees.push({nr, nc});
beetime[nr][nc] = t + 1;
}
}
}
swap(bees, nextbees);
}
cout << discrete_binary_search<int>([&](int startt) -> bool {
vvi seen(n, vi(n));
queue<ii> bear;
bear.push({mr, mc});
seen[mr][mc] = 1;
FOR(t, startt, n * n) {
F0R(_, s) {
queue<ii> nextbear;
while (!bear.empty()) {
auto [r, c] = bear.front(); bear.pop();
if (r == dr && c == dc) return false;
if (beetime[r][c] == t - 1) continue;
for (auto [nr, nc] : adjc(r, c)) {
if (0 <= nr && nr < n && 0 <= nc && nc < n && (g[nr][nc] == 'G' || g[nr][nc] == 'D') && seen[nr][nc] == 0 && beetime[nr][nc] > t) {
nextbear.push({nr, nc});
seen[nr][nc] = 1;
}
}
}
swap(bear, nextbear);
if (bear.empty()) return true;
}
}
return true;
}, 0, n * n) - 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
402 ms |
6076 KB |
Output is correct |
8 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 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 |
2 ms |
332 KB |
Output is correct |
15 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Incorrect |
18 ms |
1428 KB |
Output isn't correct |
34 |
Correct |
19 ms |
1420 KB |
Output is correct |
35 |
Correct |
88 ms |
1420 KB |
Output is correct |
36 |
Incorrect |
23 ms |
1632 KB |
Output isn't correct |
37 |
Correct |
24 ms |
1636 KB |
Output is correct |
38 |
Correct |
126 ms |
1632 KB |
Output is correct |
39 |
Incorrect |
27 ms |
2120 KB |
Output isn't correct |
40 |
Correct |
32 ms |
2160 KB |
Output is correct |
41 |
Correct |
155 ms |
2116 KB |
Output is correct |
42 |
Incorrect |
35 ms |
2608 KB |
Output isn't correct |
43 |
Correct |
38 ms |
2560 KB |
Output is correct |
44 |
Correct |
196 ms |
2556 KB |
Output is correct |
45 |
Incorrect |
45 ms |
3060 KB |
Output isn't correct |
46 |
Correct |
47 ms |
3012 KB |
Output is correct |
47 |
Correct |
239 ms |
3044 KB |
Output is correct |
48 |
Incorrect |
50 ms |
3524 KB |
Output isn't correct |
49 |
Correct |
54 ms |
3572 KB |
Output is correct |
50 |
Correct |
258 ms |
3564 KB |
Output is correct |
51 |
Incorrect |
64 ms |
4132 KB |
Output isn't correct |
52 |
Correct |
65 ms |
4128 KB |
Output is correct |
53 |
Correct |
337 ms |
4132 KB |
Output is correct |
54 |
Incorrect |
68 ms |
4744 KB |
Output isn't correct |
55 |
Correct |
76 ms |
4756 KB |
Output is correct |
56 |
Correct |
385 ms |
4712 KB |
Output is correct |
57 |
Incorrect |
80 ms |
5376 KB |
Output isn't correct |
58 |
Correct |
86 ms |
5376 KB |
Output is correct |
59 |
Correct |
453 ms |
5500 KB |
Output is correct |
60 |
Incorrect |
93 ms |
6084 KB |
Output isn't correct |
61 |
Correct |
96 ms |
6084 KB |
Output is correct |
62 |
Correct |
565 ms |
6072 KB |
Output is correct |
63 |
Correct |
339 ms |
6080 KB |
Output is correct |
64 |
Correct |
507 ms |
6052 KB |
Output is correct |
65 |
Correct |
497 ms |
6148 KB |
Output is correct |
66 |
Incorrect |
393 ms |
6052 KB |
Output isn't correct |
67 |
Correct |
402 ms |
6116 KB |
Output is correct |
68 |
Correct |
173 ms |
6128 KB |
Output is correct |
69 |
Correct |
149 ms |
6096 KB |
Output is correct |
70 |
Correct |
137 ms |
6076 KB |
Output is correct |
71 |
Correct |
141 ms |
6080 KB |
Output is correct |
72 |
Incorrect |
117 ms |
6144 KB |
Output isn't correct |
73 |
Incorrect |
152 ms |
6140 KB |
Output isn't correct |
74 |
Correct |
250 ms |
6100 KB |
Output is correct |
75 |
Correct |
292 ms |
6100 KB |
Output is correct |
76 |
Correct |
270 ms |
6100 KB |
Output is correct |
77 |
Correct |
296 ms |
6288 KB |
Output is correct |
78 |
Correct |
348 ms |
6064 KB |
Output is correct |
79 |
Correct |
212 ms |
6104 KB |
Output is correct |
80 |
Correct |
270 ms |
6096 KB |
Output is correct |
81 |
Correct |
345 ms |
6112 KB |
Output is correct |
82 |
Correct |
275 ms |
6132 KB |
Output is correct |
83 |
Correct |
359 ms |
6108 KB |
Output is correct |
84 |
Correct |
294 ms |
6156 KB |
Output is correct |
85 |
Correct |
304 ms |
6084 KB |
Output is correct |
86 |
Correct |
324 ms |
6084 KB |
Output is correct |
87 |
Correct |
323 ms |
6284 KB |
Output is correct |
88 |
Correct |
366 ms |
6072 KB |
Output is correct |
89 |
Correct |
353 ms |
6100 KB |
Output is correct |
90 |
Correct |
361 ms |
6104 KB |
Output is correct |
91 |
Correct |
387 ms |
6192 KB |
Output is correct |
92 |
Correct |
355 ms |
6088 KB |
Output is correct |