제출 #1309255

#제출 시각아이디문제언어결과실행 시간메모리
1309255avohado선물상자 (IOI15_boxes)C++20
10 / 100
1 ms580 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; #define mod 1000000007 #define maxn 200005 #define f first #define s second #define ll long long #define pb(x) push_back(x) #define mp make_pair #define all(x) x.begin(), x.end() #define len(v) max(0, (int)v.size()) long long delivery(int N, int k, int L, int p[]){ vector<int> l, r; long long ans1=0, ans2=0; for(int i=0; i<N; i++){ if(p[i]<(L+1)/2){ l.pb(p[i]); }else{ r.pb(L-p[i]); } } int i=0, j=0; reverse(all(r)); while(i<len(l)){ int d=min(k, len(l)-i); ans1+=l[i-1+d]*2; i+=d; } i=0; while(i<len(r)){ int d=min(k, len(r)-i); ans1+=r[i-1+d]*2; i+=d; } if(N<=k){ return min(ans1, 1ll*L); } if(min(len(l), len(r))==0){ return ans1; } ans2=ans1; i=max(0, len(l)-k); ans1-=l[len(l)-1]*2; if(i%k!=0){ ans1+=(l[i-1]*2); } j=len(r)-1; if(len(l)<k){ j-=k-len(l); ans1-=r[len(r)-1]*2; if(j%k!=0){ ans1+=r[j-1]*2; } } while(i<len(l)&&j>=0){ ans2=min(ans1+L, ans2); ans1+=l[i]*2; ans1-=r[i]*2; if(i%k!=1&&i!=0){ ans1-=l[i-1]*2; } if(j%k!=1&&j!=0){ ans2+=r[j-1]; } i++;j--; } return min(ans1+L, ans2); }
#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...