이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
ll ans,kam;
map<ll,ll>gg;
map<ll,ll>toz;
set<ll>posi;
ll dist(ll x,ll y){
return min(abs(x-y),toz[x]+toz[y]);
}
ll findclosest(ll x){
auto k=posi.lower_bound(x);
ll n1=-1;
ll n2=-1;
if(k!=posi.end())n1=(*k);
else{
auto d=posi.begin();
n1=(*d);
}
if(k!=posi.begin()){
auto f=k;
f--;
n2=(*f);
}
else{
auto l=posi.end();
l--;
n2=(*l);
}
if(n1!=-1 && n2==-1)return n1;
if(n1==-1 && n2!=-1)return n2;
if(dist(x,n1)>dist(x,n2))return n2;
return n1;
}
void solve(ll node,ll cap){
if(node==0){
ll f=findclosest(node);
ans+=dist(node,f);
solve(f,cap);
}
else{
while(gg[node]>0 && cap>0){
gg[node]--,cap--;
}
if(gg[node]==0){posi.erase(node);}
if(posi.size()!=0 && cap>0){
ll f=findclosest(node);
ans+=dist(node,f);
solve(f,cap);
}
else if(posi.size()==0){ans+=toz[node];return;}
else if(cap==0)ans+=toz[node],solve(0,kam);
}
return;
}
long long delivery(int N,int K,int L,int positions[])
{
kam=K;
for (ll i = 0; i < N; ++i)
{
gg[positions[i]]++;
toz[positions[i]]=min(positions[i],L-positions[i]);
posi.insert(positions[i]);
}
solve(0,K);
return ans;
}
//code the AC sol !
// BS/queue/map
# | 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... |