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 <bits/stdc++.h>
#include "boxes.h"
using namespace std;
using ll = long long;
const ll N = 10000007, inf = 1e18+10;
ll dp[N], s[N];
array<ll,2> fen[N];
void ins(ll v, int p){
int po = p;
for(;p<N;p+=p&-p){
if(v < fen[p][0]){
fen[p][0] = v;
fen[p][1] = po;
}
}
}
int get(int p){
ll mn=inf, mnpos = -1;
for(;p>0;p-=p&-p){
if(fen[p][0] < mn){
mn = fen[p][0];
mnpos = fen[p][1];
}
}
return mnpos;
}
long long delivery(int n, int k, int L, int p[]) {
ll l = L;
fill(dp, dp+N, inf);
fill(fen, fen+N, array<ll,2>{inf, -1});
for(int i = 0; i < n; ++i){
s[i] = (i ? dp[i-1] : 0) + min(2LL*(l-p[i]), l);
ins(s[i], n-i);
int pos = n-get(n-i+k-1);
// cout << pos << ' ' << get(n-i+k-1) << ' ' << (n-i+k-1) <<'\n';
dp[i] = dp[pos-1]+min({l,2LL*p[i], 2LL*(l-p[pos])});
}
return dp[n-1];
}
Compilation message (stderr)
boxes.cpp: In function 'int get(int)':
boxes.cpp:28:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
28 | return mnpos;
| ^~~~~
# | 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... |