Submission #813298

#TimeUsernameProblemLanguageResultExecution timeMemory
813298OrazBBoxes with souvenirs (IOI15_boxes)C++14
50 / 100
2040 ms7640 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second const int N = 1e7+5; ll suff[N], pref[N], dp[N]; ll F(ll x, int t, ll L){ ll cur = (t ? (L-x)*2 : x*2); return min(L, cur); } ll delivery(int n, int K, int L, int p[]){ dp[0] = min(F(p[0], 1, L), F(p[0], 0, L)); for (int i = 1; i < n; i++){ dp[i] = 1e18; for (int j = i; j >= 0; j--){ if (i-j+1 > K) break; dp[i] = min(dp[i], (j ? dp[j-1] : 0)+min(F(p[i], 0, L), F(p[j], 1, L))); } } // for (int i = 0; i < n; i++){ // if (i) pref[i] = pref[i-1]; // if ((i+1)%K == 0) pref[i] += F(p[i], 0, L); // } // for (int i = n-1; i >= 0; i--){ // suff[i] = suff[i+1]; // if ((n-i)%K == 0) suff[i] += F(p[i], 1, L); // } // ll a = suff[0], b = pref[n-1]; // if (n%K){ // a += F(p[0], 1, L); // b += F(p[n-1], 0, L); // } // ll mn = min(a, b); // for (int i = 0; i < n-1; i++){ // ll x = pref[i]; // if ((i+1)%K) x += F(p[i], 0, L); // x += suff[i+1]; // if ((n-i-1)%K) x += F(p[i+1], 1, L); // mn = min(mn, x); // } // return mn; return dp[n-1]; } // int main () // { // ios::sync_with_stdio(false); // cin.tie(0); // int n, k, l; // cin >> n >> k >> l; // int p[n]; // for (int i = 0; i < n; i++) cin >> p[i]; // cout << delivery(n, k, l, p); // } //712
#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...