Submission #630031

#TimeUsernameProblemLanguageResultExecution timeMemory
630031colossal_pepeCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
1025 ms42308 KiB
#include <iostream> #include <vector> #include <queue> #include <tuple> using namespace std; const int INF = (int)1e9 + 1; const int N = 205; int n, l, x[N], t[N], dp[N][N][N]; int dist(int x1, int x2) { if (x1 > x2) swap(x1, x2); return min(x2 - x1, l - x2 + x1); } int solve() { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { dp[i][j][k] = -INF; } } } int ans = 0; priority_queue<tuple<int, int, int, int>> pq; dp[0][n + 1][0] = 0; pq.push({0, 0, n + 1, 0}); while (not pq.empty()) { int d, i, j, c; tie(d, i, j, c) = pq.top(); ans = max(ans, c); pq.pop(); if (dp[i][j][c] != d or abs(i - j) == 1) continue; int cur = i, l = min(i, j), r = max(i, j); { // cur -> l + 1 int d_nxt = min(INF, dist(x[cur], x[l + 1]) - d); int c_nxt = (d_nxt <= t[l + 1]) + c; if (dp[l + 1][r][c_nxt] < -d_nxt) { dp[l + 1][r][c_nxt] = -d_nxt; pq.push({-d_nxt, l + 1, r, c_nxt}); } } { // cur -> r - 1 int d_nxt = min(INF, dist(x[cur], x[r - 1]) - d); int c_nxt = (d_nxt <= t[r - 1]) + c; if (dp[r - 1][l][c_nxt] < -d_nxt) { dp[r - 1][l][c_nxt] = -d_nxt; pq.push({-d_nxt, r - 1, l, c_nxt}); } } } return ans; } int main() { cin >> n >> l; x[0] = 0; for (int i = 1; i <= n; i++) { cin >> x[i]; } for (int i = 1; i <= n; i++) { cin >> t[i]; } cout << solve() << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...