Submission #813265

#TimeUsernameProblemLanguageResultExecution timeMemory
813265OrazBBoxes with souvenirs (IOI15_boxes)C++14
20 / 100
1 ms340 KiB
#include <bits/stdc++.h> // #include "boxes.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]; 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[]){ 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 mn = min(suff[0]+(n%K ? F(p[0], 1, L) : 0), pref[n-1]+(n%K ? F(p[n-1], 0, L) : 0)); 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; } // 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); // }
#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...