Submission #386627

#TimeUsernameProblemLanguageResultExecution timeMemory
386627KeshiBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
788 ms203992 KiB
//In the name of God #include <bits/stdc++.h> #include "boxes.h" using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const ll maxn = 1e7 + 100; const ll mod = 1e9 + 7; const ll inf = 1e18; #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout); #define pb push_back #define Mp make_pair #define F first #define S second #define Sz(x) ll((x).size()) #define all(x) (x).begin(), (x).end() ll dp1[maxn], dp2[maxn], mn[maxn]; long long delivery(int n, int k, int l, int p[]) { ll L = l; for(ll i = 0; i < k; i++){ dp1[i] = p[i] * 2; dp2[n - 1 - i] = (L - p[n - 1 - i]) * 2; } for(ll i = k; i < n; i++){ dp1[i] = dp1[i - k] + p[i] * 2; dp2[n - 1 - i] = dp2[n - 1 - i + k] + (L - p[n - 1 - i]) * 2; } fill(mn, mn + k, inf); ll mnn = inf; ll ans = min(dp1[n - 1], dp2[0]); ans = min(ans, L * ((n + k - 1) / k)); ll p1 = 0, p2 = k - 1; for(ll i = 0; i < n; i++){ ans = min(ans, L * ((i - 1) / k) + mn[p2] + dp2[i]); ans = min(ans, L * ((i - 1) / k) + mnn + dp2[i] + L); ans = min(ans, dp2[i] + L * ((i + k - 1) / k)); ans = min(ans, dp1[i] + L * ((n - i - 1 + k - 1) / k)); mn[p1] = min(mn[p1], dp1[i] - L * (i / k)); mnn = min(mnn, mn[p1]); p1++; if(p1 == k) p1 = 0; p2++; if(p2 == k) p2 = 0; } return ans; } /*int main(){ int n, k, L, p[100]; cin >> n >> k >> L; for(ll i = 0; i < n; i++){ cin >> p[i]; } cout << "ans : " << delivery(n, k, L, p) << "\n"; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...