Submission #387433

#TimeUsernameProblemLanguageResultExecution timeMemory
387433AmineTrabelsiBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
2 ms364 KiB
#include <bits/stdc++.h> #include "boxes.h" /* g++ -DEVAL -static -O2 -std=c++17 -o boxes -Wall -Wshadow -Wextra -Wconversion grader.cpp boxes.cpp */ using namespace std; long long delivery(int N, int K, int L, int p[]) { deque<int> dq; int z = 0; for(int i=0;i<N;i++){ dq.push_back(p[i]); if(p[i] == 0)z++; } auto cost_right = [&](){ int ind = min(K,(int)dq.size())-1; if(ind < 0 || ind >= (int)dq.size())return 0; return dq[ind]+min(dq[ind],L-dq[ind]); }; auto cost_left = [&](){ int cnt = z; if(cnt > K)return 0; int ind = min(K-cnt,(int)dq.size()-cnt); if(ind < 0 || ind > (int)dq.size())return 0; return L-dq[(int)dq.size()-ind] + min(dq[(int)dq.size()-ind],L-dq[(int)dq.size()-ind]); }; long long res = 0; int cnt = N; while(cnt>0){ int R = cost_right(); int LL = cost_left(); if(R <= LL){ int x = K; int dist = 0; while(x-- && !dq.empty()){ dist = max(dist,dq.front()*2); dq.pop_front(); } res += R; }else{ int x = K; int dist = 0; while(x-- && !dq.empty()){ if(dq.front() == 0){ dist = max(dist,dq.front()*2); dq.pop_front(); }else { dist = max(dist,(L-dq.back())*2); dq.pop_back(); } } res += LL; } z=max(z-K,0); cnt-=K; } return res; }
#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...