# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789653 | 2023-07-21T16:06:29 Z | phongcd | Mecho (IOI09_mecho) | C++14 | 5 ms | 404 KB |
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define ii pair <int, int> #define ill pair <ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define file "test" using namespace std; const ll N = 8e2 + 2; const ll MOD = 1e9; const ll INF = 1e18; const ll base = 311; const int BLOCK_SIZE = 2000; int n, s; ii start, target, d[N][N]; char a[N][N]; int mtime[N][N]; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; void addstep(ii &a) { a.se += 1; if (a.se > s) a.fi ++, a.se = 1; } bool cmp(ii a, ii b) { if (a.fi != b.fi) return a.fi < b.fi; return a.se < b.se; } bool check(int x) { for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) d[i][j] = {2e9, 0}; queue <ii> h; h.push(start); d[start.fi][start.se] = {x + 1, 0}; while (!h.empty()) { auto [x, y] = h.front(); h.pop(); ii res = d[x][y]; addstep(res); for (int j = 0; j <= 3; j ++) { int u = x + dx[j]; int v = y + dy[j]; if (a[u][v] == 'G' && res.fi <= mtime[u][v] && !cmp(d[u][v], res)) { h.push({u, v}); d[u][v] = res; } } } return d[target.fi][target.se].fi != 2e9; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen(file".inp","r",stdin); freopen(file".out","w",stdout); #endif cin >> n >> s; queue <ii> bee; for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) { cin >> a[i][j]; mtime[i][j] = 2e9; if (a[i][j] == 'H') bee.push({i, j}), mtime[i][j] = 0; if (a[i][j] == 'M') a[i][j] = 'G', start = {i, j}; if (a[i][j] == 'D') a[i][j] = 'G', target = {i, j}; } while (!bee.empty()) { auto [x, y] = bee.front(); bee.pop(); int res = mtime[x][y] + 1; for (int j = 0; j <= 3; j ++) { int u = x + dx[j]; int v = y + dy[j]; if (a[u][v] == 'G' && mtime[u][v] > res) { bee.push({u, v}); mtime[u][v] = res; } } } int l = 1, r = 2e3; while (l < r) { int mid = l + (r - l + 1) / 2; if (check(mid)) l = mid; else r = mid - 1; } cout << (check(l) ? l : -1); } /* /\_/\ zzZ (= -_-) / >u >u */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 340 KB | Output isn't correct |
2 | Incorrect | 2 ms | 340 KB | Output isn't correct |
3 | Incorrect | 2 ms | 340 KB | Output isn't correct |
4 | Incorrect | 2 ms | 340 KB | Output isn't correct |
5 | Incorrect | 2 ms | 340 KB | Output isn't correct |
6 | Incorrect | 2 ms | 340 KB | Output isn't correct |
7 | Incorrect | 2 ms | 340 KB | Output isn't correct |
8 | Incorrect | 1 ms | 340 KB | Output isn't correct |
9 | Incorrect | 2 ms | 340 KB | Output isn't correct |
10 | Incorrect | 2 ms | 340 KB | Output isn't correct |
11 | Incorrect | 2 ms | 340 KB | Output isn't correct |
12 | Incorrect | 2 ms | 340 KB | Output isn't correct |
13 | Incorrect | 2 ms | 340 KB | Output isn't correct |
14 | Incorrect | 2 ms | 340 KB | Output isn't correct |
15 | Incorrect | 2 ms | 340 KB | Output isn't correct |
16 | Incorrect | 2 ms | 340 KB | Output isn't correct |
17 | Incorrect | 2 ms | 340 KB | Output isn't correct |
18 | Incorrect | 2 ms | 340 KB | Output isn't correct |
19 | Incorrect | 1 ms | 340 KB | Output isn't correct |
20 | Incorrect | 1 ms | 340 KB | Output isn't correct |
21 | Incorrect | 2 ms | 340 KB | Output isn't correct |
22 | Incorrect | 2 ms | 340 KB | Output isn't correct |
23 | Incorrect | 1 ms | 340 KB | Output isn't correct |
24 | Incorrect | 2 ms | 340 KB | Output isn't correct |
25 | Incorrect | 2 ms | 340 KB | Output isn't correct |
26 | Incorrect | 2 ms | 340 KB | Output isn't correct |
27 | Incorrect | 2 ms | 340 KB | Output isn't correct |
28 | Incorrect | 2 ms | 328 KB | Output isn't correct |
29 | Incorrect | 1 ms | 340 KB | Output isn't correct |
30 | Incorrect | 2 ms | 340 KB | Output isn't correct |
31 | Incorrect | 1 ms | 340 KB | Output isn't correct |
32 | Incorrect | 1 ms | 340 KB | Output isn't correct |
33 | Incorrect | 2 ms | 340 KB | Output isn't correct |
34 | Incorrect | 2 ms | 340 KB | Output isn't correct |
35 | Incorrect | 2 ms | 340 KB | Output isn't correct |
36 | Incorrect | 2 ms | 340 KB | Output isn't correct |
37 | Incorrect | 2 ms | 340 KB | Output isn't correct |
38 | Incorrect | 1 ms | 340 KB | Output isn't correct |
39 | Incorrect | 2 ms | 340 KB | Output isn't correct |
40 | Incorrect | 2 ms | 340 KB | Output isn't correct |
41 | Incorrect | 2 ms | 340 KB | Output isn't correct |
42 | Incorrect | 2 ms | 340 KB | Output isn't correct |
43 | Incorrect | 1 ms | 340 KB | Output isn't correct |
44 | Incorrect | 2 ms | 340 KB | Output isn't correct |
45 | Incorrect | 2 ms | 340 KB | Output isn't correct |
46 | Incorrect | 2 ms | 340 KB | Output isn't correct |
47 | Incorrect | 2 ms | 340 KB | Output isn't correct |
48 | Incorrect | 3 ms | 340 KB | Output isn't correct |
49 | Incorrect | 2 ms | 340 KB | Output isn't correct |
50 | Incorrect | 2 ms | 340 KB | Output isn't correct |
51 | Incorrect | 2 ms | 340 KB | Output isn't correct |
52 | Incorrect | 2 ms | 340 KB | Output isn't correct |
53 | Incorrect | 2 ms | 340 KB | Output isn't correct |
54 | Incorrect | 2 ms | 340 KB | Output isn't correct |
55 | Incorrect | 2 ms | 340 KB | Output isn't correct |
56 | Incorrect | 2 ms | 396 KB | Output isn't correct |
57 | Incorrect | 2 ms | 340 KB | Output isn't correct |
58 | Incorrect | 2 ms | 340 KB | Output isn't correct |
59 | Incorrect | 2 ms | 340 KB | Output isn't correct |
60 | Incorrect | 1 ms | 340 KB | Output isn't correct |
61 | Incorrect | 1 ms | 340 KB | Output isn't correct |
62 | Incorrect | 2 ms | 340 KB | Output isn't correct |
63 | Incorrect | 1 ms | 340 KB | Output isn't correct |
64 | Incorrect | 2 ms | 340 KB | Output isn't correct |
65 | Incorrect | 2 ms | 304 KB | Output isn't correct |
66 | Incorrect | 2 ms | 340 KB | Output isn't correct |
67 | Incorrect | 2 ms | 340 KB | Output isn't correct |
68 | Incorrect | 3 ms | 340 KB | Output isn't correct |
69 | Incorrect | 2 ms | 340 KB | Output isn't correct |
70 | Incorrect | 2 ms | 340 KB | Output isn't correct |
71 | Incorrect | 2 ms | 340 KB | Output isn't correct |
72 | Incorrect | 2 ms | 340 KB | Output isn't correct |
73 | Incorrect | 2 ms | 340 KB | Output isn't correct |
74 | Incorrect | 1 ms | 340 KB | Output isn't correct |
75 | Incorrect | 2 ms | 340 KB | Output isn't correct |
76 | Incorrect | 1 ms | 340 KB | Output isn't correct |
77 | Incorrect | 2 ms | 340 KB | Output isn't correct |
78 | Incorrect | 1 ms | 340 KB | Output isn't correct |
79 | Incorrect | 1 ms | 340 KB | Output isn't correct |
80 | Incorrect | 2 ms | 340 KB | Output isn't correct |
81 | Incorrect | 1 ms | 340 KB | Output isn't correct |
82 | Incorrect | 2 ms | 340 KB | Output isn't correct |
83 | Incorrect | 2 ms | 340 KB | Output isn't correct |
84 | Incorrect | 1 ms | 340 KB | Output isn't correct |
85 | Incorrect | 2 ms | 340 KB | Output isn't correct |
86 | Incorrect | 1 ms | 340 KB | Output isn't correct |
87 | Incorrect | 2 ms | 340 KB | Output isn't correct |
88 | Incorrect | 2 ms | 340 KB | Output isn't correct |
89 | Incorrect | 2 ms | 340 KB | Output isn't correct |
90 | Incorrect | 5 ms | 404 KB | Output isn't correct |
91 | Incorrect | 2 ms | 340 KB | Output isn't correct |
92 | Incorrect | 3 ms | 340 KB | Output isn't correct |