# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
696343 | 2023-02-06T09:17:09 Z | jhwest2 | Climbers (RMI18_climbers) | C++14 | 762 ms | 431672 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef array<int, 3> P; const int N = 5050; const ll INF = 1e18 + 10; int n, a[N], p; ll dp[2 * N][2 * N]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { int x; cin >> x; if (p && a[p - 1] == x) continue; while (p >= 2 && (a[p - 2] < a[p - 1]) == (a[p - 1] < x)) --p; a[p++] = x; } n = p; for (int i = 0; i <= 2 * n - 2; i++) for (int j = i; j <= 2 * n - 2; j++) dp[i][j] = INF; dp[0][2 * n - 2] = 0; auto go = [&](int x, int y, int tx, int ty) { int p = (x & 1) ? a[y / 2] : a[x / 2]; int nx = (x & 1) ? (tx ? x + 1 : x - 1) : (tx ? x + 2 : x - 2); int ny = (y & 1) ? (ty ? y - 1 : y + 1) : (ty ? y - 2 : y + 2); bool dx = (tx ? a[nx / 2 - 1] : a[nx / 2 + 1]) < a[nx / 2]; // true if climbing bool dy = (ty ? a[ny / 2 + 1] : a[ny / 2 - 1]) < a[ny / 2]; if (dx != dy) return P{ -1, -1, 0 }; if (a[nx / 2] == a[ny / 2]) return P{ nx, ny, abs(a[nx / 2] - p) }; if (dx == (a[nx / 2] < a[ny / 2])) return P{ nx, ty ? ny + 1 : ny - 1, abs(a[nx / 2] - p) }; else return P{ tx ? nx - 1 : nx + 1, ny, abs(a[ny / 2] - p) }; }; for (int d = 2 * n - 2; d >= 1; d--) { for (int l = 0; l + d <= 2 * n - 2; l++) { int r = l + d; if (dp[l][r] == INF) continue; auto [x, y, d] = go(l, r, 1, 1); // alice, bob goes forward if (x != -1) dp[x][y] = min(dp[x][y], dp[l][r] + d); if (l != 0) { auto [x, y, d] = go(l, r, 0, 1); // only bob goes forward if (x != -1) dp[x][y] = min(dp[x][y], dp[l][r] + d); } if (r != 2 * n - 2) { auto [x, y, d] = go(l, r, 1, 0); // only alice goes forward if (x != -1) dp[x][y] = min(dp[x][y], dp[l][r] + d); } } } ll ans = INF; for (int i = 0; i < n; i++) ans = min(ans, dp[2 * i][2 * i]); cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 1236 KB | Output isn't correct |
2 | Incorrect | 3 ms | 4180 KB | Output isn't correct |
3 | Incorrect | 27 ms | 24192 KB | Output isn't correct |
4 | Incorrect | 257 ms | 165568 KB | Output isn't correct |
5 | Incorrect | 762 ms | 431672 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 468 KB | Output is correct |
2 | Incorrect | 1 ms | 724 KB | Output isn't correct |
3 | Incorrect | 1 ms | 1876 KB | Output isn't correct |
4 | Incorrect | 1 ms | 1236 KB | Output isn't correct |
5 | Incorrect | 3 ms | 5844 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 1108 KB | Output isn't correct |
2 | Incorrect | 2 ms | 3796 KB | Output isn't correct |
3 | Incorrect | 21 ms | 22596 KB | Output isn't correct |
4 | Incorrect | 253 ms | 152192 KB | Output isn't correct |
5 | Incorrect | 248 ms | 150924 KB | Output isn't correct |
6 | Incorrect | 507 ms | 275768 KB | Output isn't correct |
7 | Incorrect | 467 ms | 260804 KB | Output isn't correct |
8 | Incorrect | 697 ms | 390636 KB | Output isn't correct |
9 | Incorrect | 709 ms | 397864 KB | Output isn't correct |
10 | Incorrect | 693 ms | 389072 KB | Output isn't correct |