Submission #30986

#TimeUsernameProblemLanguageResultExecution timeMemory
30986kajebiiiBoxes with souvenirs (IOI15_boxes)C++14
20 / 100
2 ms376 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define SZ(v) ((int)(v).size()) #define ALL(v) (v).begin(),(v).end() #define one first #define two second typedef long long ll; typedef pair<double, double> pd; typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; typedef pair<ll, pi> plp; typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli; const int INF = 0x3f2f1f0f; const ll LINF = 1ll * INF * INF * 2; int N, K, L; deque<int> Ps; ll delivery(int n, int k, int l, int p[]) { N = n; K = k; L = l; for(int i=0; i<N; i++) Ps.push_back(p[i]); while(SZ(Ps) > 0 && Ps.front() == 0) Ps.pop_front(); ll ans = 0; while(SZ(Ps) > 0) { int lix = min(K-1, SZ(Ps)-1); if(Ps[lix] <= L/2) { ans += Ps[lix] * 2; for(int i=0; i<=lix; i++) Ps.pop_front(); }else break; } while(SZ(Ps) > 0) { int rix = max(SZ(Ps)-K, 0); if(Ps[rix] >= (L+1)/2) { ans += (L - Ps[rix]) * 2; for(int i=SZ(Ps)-1; i>=rix; i--) Ps.pop_back(); }else break; } if(SZ(Ps) > 0) { int maxV = 0, minV = L; for(int x : Ps) { if(x <= L/2) maxV = max(maxV, x); if(x >= (L+1)/2) minV = min(minV, x); } // printf("%d %d\n", maxV, minV); int val = (maxV * 2 + (L - minV) * 2); if(SZ(Ps) > K) { int lix = K; int rix = SZ(Ps) - K - 1; ans += min(val, L + min(Ps[rix] * 2, (L - Ps[lix]) * 2)); }else{ ans += min(val, L); } } 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...