제출 #1005977

#제출 시각아이디문제언어결과실행 시간메모리
1005977Ludissey선물상자 (IOI15_boxes)C++14
0 / 100
1 ms604 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() int N,K,L; int clst(int x){ if(x>L/2) x=L-x; return (x)*2; } long long delivery(signed _n, signed _k, signed _l, signed p[]) { N=_n; K=_k; L=_l; vector<int> a(N); vector<int> marked(N); for (int i = 0; i < N; i++) a[i]=p[i]; sort(a.begin(),a.end()); int sumFULL=1e9; int sumNOTFULL=0; int lmt=N; vector<pair<int,int>> res; vector<int> res2; vector<int> res3; for (int i = 0; i < N; i++) { res.push_back({abs(L-2*a[i]),i}); } sort(all(res)); for (int i = 0; i < sz(res); i++) { if(i<K) res3.push_back(res[i].second); else { res3.push_back(res[i].second); res2.push_back(res[i].second); } } sort(all(res2)); sort(all(res3)); vector<int> prf1(sz(res2)); lmt=sz(a); for (int i = 0; i < sz(a); i++) { if(a[i]>L/2) { lmt=i; break; } } for (int i = 0; i < lmt; i++) { if(i<K) prf1[i]=a[i]*2; else prf1[i]=a[i]*2+prf1[i-K]; } for (int i = lmt; i < sz(res2); i--) { if(i<lmt+K) prf1[i]=(L-a[i])*2; else prf1[i]=(L-a[i])*2+prf1[i-K]; } for (int i = max(0LL,lmt-K); i <= min(sz(a)-1,K+lmt); i++) sumFULL=min(sumFULL, L+prf1[i]+prf1[i+K]); for (int i = lmt-1; i >= 0; i-=K) sumNOTFULL+=a[i]*2; for (int i = lmt; i < sz(a); i+=K) sumNOTFULL+=(L-a[i])*2; return min(sumFULL,sumNOTFULL); }
#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...