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 <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;
//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007
typedef long long ll;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
const ll MAXN = 10000010;
ll li[MAXN], ri[MAXN];
long long delivery(int N, int K, int L, int p[]) {
// ios_base :: sync_with_stdio(false);
// cin.tie(nullptr);
// cin >> N >> K >> L;
// for (ll i = 0; i<N; i++) {
// cin >> p[i];
// }
for (ll i = 0; i<N; i++) {
li[i+1] = p[i]-(i-K < 0 ? 0 : p[i-K])+li[max(i-K+1, 0ll)]+(i-K >= 0 ? 2*p[i-K] : 0);
}
ll curr = 0;
for (ll i = N-1; i>=0; i--) {
curr++;
ri[curr] = (i+K > N-1 ? L : p[i+K])-p[i]+ri[max(curr-K, 0ll)]+2*(L-(i+K<N ? p[i+K] : L));
}
ll best = 1e13;
for (ll i = 0; i<=N; i++) {
best = min(best, li[i]+ri[N-i]+(i != 0 ? p[i-1] : 0)+(i != N ? L-p[N-i-1] : 0));
}
for (ll i = 0; i<=N-K; i++) {
best = min(best, li[i]+L+ri[N-i-K]+(i!=0 ? p[i-1] : 0)+(i != N-K ? L-p[N-i-K-1] : 0));
}
return best;
}
//ll N, K, L, p[MAXN];
//
//int main() {
// ios_base :: sync_with_stdio(false);
// cin.tie(nullptr);
// cin >> N >> K >> L;
// for (ll i = 0; i<N; i++) {
// cin >> p[i];
// }
// for (ll i = 0; i<N; i++) {
// li[i+1] = p[i]-(i-K < 0 ? 0 : p[i-K])+li[max(i-K+1, 0ll)]+(i-K >= 0 ? 2*p[i-K] : 0);
// }
// ll curr = 0;
// for (ll i = N-1; i>=0; i--) {
// curr++;
// ri[curr] = (i+K > N-1 ? L : p[i+K])-p[i]+ri[max(curr-K, 0ll)]+2*(L-(i+K<N ? p[i+K] : L));
// }
// ll best = 1e13;
// for (ll i = 0; i<=N; i++) {
// best = min(best, li[i]+ri[N-i]+(i != 0 ? p[i-1] : 0)+(i != N ? L-p[N-i-1] : 0));
// }
// for (ll i = 0; i<=N-K; i++) {
// best = min(best, li[i]+L+ri[N-i-K]+(i!=0 ? p[i-1] : 0)+(i != N-K ? L-p[N-i-K-1] : 0));
// }
// cout << best << "\n";
// return 0;
//}
//
# | 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... |