This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<double, double> pd;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF * 2;
const int MAX_N = 1e7 + 100;
int N, K, L, P[MAX_N];
ll Ls[MAX_N], Rs[MAX_N];
deque<int> Ps;
ll delivery(int n, int k, int l, int p[]) {
N = n; K = k; L = l;
for(int i=0; i<N; i++) Ps.push_back(p[i]);
while(SZ(Ps) > 0 && Ps.front() == 0) Ps.pop_front();
for(int i=0; i<SZ(Ps); i++) P[i+1] = Ps[i];
N = SZ(Ps);
P[0] = 0; P[N+1] = L;
for(int i=1; i<=N; i++) {
int cnt = i-1;
if(cnt % K == 0) Ls[i] = Ls[i-1] + P[i] * 2;
else Ls[i] = Ls[i-1] + (P[i] - P[i-1]) * 2;
}
for(int i=N; i>=1; i--) {
int cnt = N - i;
if(cnt % K == 0) Rs[i] = Rs[i+1] + (L-P[i]) * 2;
else Rs[i] = Rs[i+1] + (P[i+1] - P[i]) * 2;
}
ll ans = LINF;
int rix = N+1;
for(int i=1; i<=N; i++) if(P[i] > L/2) {rix = i; break;}
for(int i=0; i<rix; i++) {
ll val = Ls[i];
int lix = i+1;
ll times = ((rix - lix + K-1) / K);
val += times * L;
lix = min(lix + times * K, 1ll*N+1);
val += Rs[lix];
ans = min(ans, val);
}
return ans;
}
Compilation message (stderr)
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:52:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
lix = min(lix + times * K, 1ll*N+1);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |