Submission #1267353

#TimeUsernameProblemLanguageResultExecution timeMemory
1267353gayCollecting Stamps 3 (JOI20_ho_t3)C++20
15 / 100
1758 ms1114112 KiB
#include <bits/stdc++.h> #include <experimental/random> #include <random> using namespace std; using ll = long long; using ld = long double; const ll INF = 1e18, MOD = 998244353; void solve(); signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll q = 1; //cin >> q; while (q--) { solve(); } } unordered_map<ll, ll> dp[401][401][2]; void solve() { ll n, all; cin >> n >> all; vector<ll> x(n); ll prev = 0; for (int i = 0; i < n; i++) { ll t; cin >> t; x[i] = t - prev; prev = t; } vector<ll> t(n); for (int i = 0; i < n; i++) { cin >> t[i]; } vector<ll> a; for (int i = 0; i < n; i++) { a.push_back(t[i]); } a.push_back(INF); for (int i = 0; i < n; i++) { a.push_back(t[i]); } vector<ll> b; for (int i = 1; i < n; i++) { b.push_back(x[i]); } b.push_back(all - prev); for (int i = 0; i < n; i++) { b.push_back(x[i]); } vector<ll> pref = {0}; for (auto i : b) { pref.push_back(pref.back() + i); } dp[n][n][0][0] = 0; ll ans = 0; for (int len = 1; len <= n + 1; len++) { for (int l = 0; l + len <= 2 * n + 1; l++) { ll r = l + len - 1; for (auto [time, cnt] : dp[l][r][0]) { ans = max(ans, cnt); if (len == n + 1) { continue; } ll nw_time = time + b[l - 1]; ll cost = cnt; if (nw_time <= a[l - 1]) { cost++; } dp[l - 1][r][0][nw_time] = max(dp[l - 1][r][0][nw_time], cost); nw_time = time + pref[r + 1] - pref[l]; cost = cnt; if (nw_time <= a[r + 1]) { cost++; } dp[l][r + 1][1][nw_time] = max(dp[l][r + 1][1][nw_time], cost); } for (auto [time, cnt] : dp[l][r][1]) { ans = max(ans, cnt); if (len == n + 1) { continue; } ll nw_time = time + pref[r] - pref[l - 1]; ll cost = cnt; if (nw_time <= a[l - 1]) { cost++; } dp[l - 1][r][0][nw_time] = max(dp[l - 1][r][0][nw_time], cost); nw_time = time + b[r]; cost = cnt; if (nw_time <= a[r + 1]) { cost++; } dp[l][r + 1][1][nw_time] = max(dp[l][r + 1][1][nw_time], cost); } } } 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...