Submission #367301

#TimeUsernameProblemLanguageResultExecution timeMemory
367301piddddgyCollecting Stamps 3 (JOI20_ho_t3)C++11
0 / 100
151 ms244972 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define cerr if(false) cerr #define watch(x) cerr << (#x) << " is " << (x) << endl; #define endl '\n' #define ld long double #define int long long #define pii pair<int, int> #define fi first #define se second #define sz(a) (int)(a).size() #define all(x) (x).begin(), (x).end() const int maxn = 250; int n, l; int x[maxn], t[maxn]; // [l][r][where][taken] = time int dp[maxn][maxn][2][maxn]; int mod(int num) { return (num+n)%n; } int dist(int x, int y) { int res = abs(x-y); res = min(res, l-res); return res; } signed main() { ios::sync_with_stdio(0); cin.tie(0); for(int i = 0; i < maxn; i++) { for(int j = 0; j < maxn; j++) { for(int k = 0; k < 2; k++) { for(int l = 0; l < maxn; l++) { dp[i][j][k][l] = 1e18; } } } } cin >> n >> l; for(int i = 1; i <= n; i++) { cin >> x[i]; } for(int i = 1; i <= n; i++) { cin >> t[i]; } dp[0][0][0][0] = dp[0][0][1][0] = 0; n++; int ans = 0; // length of interval including 0 (top of circle) for(int len = 2; len <= n; len++) { for(int st = 1-len; st <= 0; st++) { int l = mod(st); int r = mod(l+len-1); for(int i = 0; i <= n; i++) { // left, right int l2 = mod(l+1); int r2 = mod(r-1); dp[l][r][0][i] = min({dp[l][r][0][i], dp[l2][r][0][i] + dist(x[l], x[l2]), dp[l2][r][0][i] + dist(x[l], x[r])}); dp[l][r][1][i] = min({dp[l][r][1][i], dp[l][r2][0][i] + dist(x[r], x[l]), dp[l][r2][1][i] + dist(x[r], x[r2])}); if(i) { // TAKE LEFT // last take left if(dp[l2][r][0][i-1] + dist(x[l], x[l2]) <= t[l]) { dp[l][r][0][i] = min(dp[l][r][0][i], dp[l2][r][0][i-1] + dist(x[l], x[l2])); } // last take right if(dp[l2][r][1][i-1] + dist(x[l], x[r]) <= t[l]) { dp[l][r][0][i] = min(dp[l][r][0][i], dp[l2][r][1][i-1] + dist(x[l], x[r])); } // TAKE RIGHT // last taken left if(dp[l][r2][0][i-1] + dist(x[l], x[r]) <= t[r]) { dp[l][r][1][i] = min(dp[l][r][1][i], dp[l][r2][0][i-1] + dist(x[l], x[r])); } if(dp[l][r2][1][i-1] + dist(x[r2], x[r]) <= t[r]) { dp[l][r][1][i] = min(dp[l][r][1][i], dp[l][r2][1][i-1] + dist(x[r2], x[r])); } } if(min(dp[l][r][0][i], dp[l][r][1][i]) != 1e18) { ans = max(ans, i); } } } } cout << ans << endl; } /* [bitmask][current][time] 9 600 000 6 25 3 4 7 17 21 23 11 7 17 10 8 10 -> 4 5 20 4 5 8 13 17 18 23 15 7 10 -> 5 Did you read the bounds? Did you make typos? Are there edge cases (N=1?) Are array sizes proper? Integer overflow? DS reset properly between test cases? Is using long longs causing TLE? Are you using floating points? */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...