Submission #1162215

#TimeUsernameProblemLanguageResultExecution timeMemory
1162215gustavo_dBoxes with souvenirs (IOI15_boxes)C++20
70 / 100
2096 ms195948 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; ll delivery(int n, int k, int len, int p[]) { ll ans = INF; ll dpL[n+1]; dpL[0] = 0; ll dpR[n+1]; dpR[0] = 0; for (int i=0; i<=n; i++) { if (i != 0 and i <= k) dpL[i] = 2*p[i-1]; else if (i != 0) dpL[i] = 2*p[i-1] + dpL[i-k]; } for (int j=0; j<=n; j++) { if (j != 0 and j <= k) dpR[j] = 2*(len - p[n-j]); else if (j != 0) dpR[j] = 2LL*(len-p[n-j]) + dpR[j-k]; } int pt = -1; for (int i=0; i<n; i++) { if (p[i] <= len / 2) pt = i; else break; } // O(k^2) if (k * k <= 1000000 or true) { for (int i=max(0, pt - k - 5); i<=pt+1; i++) { for (int j=max(0, n-pt-k-5); j<=n-pt-1; j++) { if (n - i - j > k) continue; ll tmp = (i + j < n ? len : 0); tmp += dpL[i] + dpR[j]; // cout << i << ' ' << j << ' ' << tmp << endl; ans = min(ans, tmp); } // cout << endl << endl; } } else { // k >= 10^3 => } return 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...