이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a; i<int(b); i++)
#define all(x) x.begin(),x.end()
long long delivery(int N, int K, int L, int p[]) {
if (K==1) {
long long tot=0;
rep(i,0,N) {
tot+=2*min(p[i],L-p[i]);
}
return tot;
}
map<long long,int> places;
long long biggestplace=0;
rep(i,0,N) {
long long curr=p[i];
biggestplace=max(biggestplace,curr);
if (places.find(curr)!=places.begin()) places[curr]++;
else places[curr]=1;
}
map<int,long long> dpthing; //This dp should be, for every possible amount of boxes that chould have been transported
//to all the teams before and including the place we are at, minimum time to get there with those boxes
dpthing.insert(make_pair(0,0));
long long prevplace=0;
long long extratime=0;
int need=0;
for (auto a:places) {
long long loc=a.first;
int amount=a.second;
extratime+=(amount/K)*8*min(loc,L-loc);
amount%=K;
if (amount==0) continue;
long long mintime=1000000000000000;
need+=amount;
vector<int> rem;
for (auto b:dpthing) {
int have=b.first;
mintime=min(mintime,b.second);
if (have>=need) break;
rem.push_back(have);
}
for (auto b:rem) {
dpthing.erase(b);
}
//Now everything in dpthing has enough for this new location, they move there and increase time by the distance
extratime+=min(loc-prevplace,L-loc+prevplace);
//We can also go back and fetch new boxes, this should be added to the previous smallest mintime
mintime+=min(prevplace,L-prevplace) + min(loc,L-loc); //Time to go back and fetch more and go to new place
mintime-=min(loc-prevplace,L-loc+prevplace); //This was added to extratime instead
dpthing.insert(make_pair(need-amount+K,mintime)); //We would have need-amount+K after that
prevplace=loc;
}
//Now we take the least value in dpthing, add time to get back and extratime to it
long long best=1000000000000000;
for (auto a:dpthing) {
best=min(best,a.second);
}
return best + min(biggestplace,L-biggestplace) + extratime;
}
# | 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... |