Submission #639890

#TimeUsernameProblemLanguageResultExecution timeMemory
639890danikoynovCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
176 ms135268 KiB
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 210; const ll inf = 1e18; int n; ll l, x[maxn], t[maxn], dp[maxn][maxn][maxn][2]; void solve() { cin >> n >> l; for (int i = 1; i <= n; i ++) cin >> x[i]; for (int i = 1; i <= n; i ++) cin >> t[i]; x[n + 1] = l; for (int i = 0; i <= n + 1; i ++) for (int j = 0; j <= n + 1; j ++) for (int f = 0; f <= n + 1; f ++) dp[i][j][f][0] = dp[i][j][f][1] = inf; dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0; ll ans = 0; for (int f = 0; f <= n + 1; f ++) { for (int d = n; d > 0; d --) { for (int i = 0; i <= n - d + 1; i ++) { int j = i + d; if (i != 0) { dp[i][j][f][0] = min(dp[i][j][f][0], dp[i - 1][j][f][0] + x[i] - x[i - 1]); if (f > 0) { ll tp = dp[i - 1][j][f - 1][0] + x[i] - x[i - 1]; if (tp <= t[i]) dp[i][j][f][0] = min(dp[i][j][f][0], tp); } } if (j != n + 1) { dp[i][j][f][1] = min(dp[i][j][f][1], dp[i][j + 1][f][1] + x[j + 1] - x[j]); if (f > 0) { ll tp = dp[i][j + 1][f - 1][1] + x[j + 1] - x[j]; if (tp <= t[j]) { dp[i][j][f][1] = min(dp[i][j][f][1], tp); } } } if (dp[i][j][f][0] + x[i] + l - x[j] < dp[i][j][f][1]) dp[i][j][f][1] = dp[i][j][f][0] + x[i] + l - x[j]; if (dp[i][j][f][1] + x[i] + l - x[j] < dp[i][j][f][0]) dp[i][j][f][0] = dp[i][j][f][1] + x[i] + l - x[j]; if (dp[i][j][f][0] != inf || dp[i][j][f][1] != inf) ans = max(ans, (ll)f); ///cout << i << " " << j << " " << f << " " << dp[i][j][f][0] << " " << dp[i][j][f][1] << endl; } } } cout << ans << endl; } int main() { solve(); 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...