이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define ff first
#define ss second
#define ln "\n"
using namespace std;
vector<ll> pos;
ll n, k, l;
long long delivery(int N, int K, int L, int p[]) {
n=N; k=K; l=L;
pos.resize(n);
vector<pair<ll, ll>> dist(n);
for (ll i=0; i<n; i++){
pos[i] = p[i];
dist[i] = {min((ll)p[i], l-p[i]), i};
}
sort(dist.begin(), dist.end());
vector<ll> lsi, rsi;
for (ll i=0; i<(ll)dist.size()-k; i++){
if (pos[dist[i].ss]<=l/2){
lsi.push_back(dist[i].ss);
}else{
rsi.push_back(dist[i].ss);
}
}
ll ans=l;
for (ll i=lsi.size()-1; i>=0; i-=k){
ans+=pos[lsi[i]]*2;
}
for (ll i=rsi.size()-1; i>=0; i-=k){
ans+=(l-pos[rsi[i]])*2;
}
for (ll i=(ll)dist.size()-k; i<(ll)dist.size(); i++){
if (pos[dist[i].ss]<=l/2){
lsi.push_back(dist[i].ss);
}else{
rsi.push_back(dist[i].ss);
}
}
ll aans=0;
for (ll i=lsi.size()-1; i>=0; i-=k){
aans+=pos[lsi[i]]*2;
}
for (ll i=rsi.size()-1; i>=0; i-=k){
aans+=(l-pos[rsi[i]])*2;
}
// cout << aans << " " << ans << ln;
// cout << "Answer: " << min(ans, aans) << ln;
return min(aans, ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |