Submission #201950

#TimeUsernameProblemLanguageResultExecution timeMemory
201950kuroniCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
420 ms131576 KiB
#include <bits/stdc++.h> using namespace std; const int N = 205; const long long INF = 1E18 + 7; int n, l, cur, le, ri, ans = 0, x[N], d[N]; long long dst, dp[N][N][N][2]; void mini(long long &cur, long long tmp) { if (tmp < cur) { cur = tmp; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> l; for (int i = 1; i <= n; i++) { cin >> x[i]; } for (int i = 1; i <= n; i++) { cin >> d[i]; } n++; 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][0] = dp[i][j][k][1] = INF; } } } dp[0][0][0][0] = 0; for (int k = 0; k < n; k++) { for (int len = 0; len < n; len++) { for (int i = 0; i < n; i++) { for (int t = 0; t < 2; t++) { if (dp[i][len][k][t] == INF) { continue; } cur = (t == 0 ? i : (i + len) % n); le = (i + n - 1) % n; ri = (i + len + 1) % n; dst = min(l - abs(x[cur] - x[le]), abs(x[cur] - x[le])) + dp[i][len][k][t]; mini(dp[le][len + 1][k + (dst <= d[le])][0], dst); dp[le][len + 1][k + (dst <= d[le])][0] = min(dp[le][len + 1][k + (dst <= d[le])][0], dst); dst = min(l - abs(x[cur] - x[ri]), abs(x[cur] - x[ri])) + dp[i][len][k][t]; mini(dp[i][len + 1][k + (dst <= d[ri])][1], dst); ans = max(ans, k); } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...