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;
using ll = long long;
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
int n,k,l,a[10000010];
vector<pi> pos;
ll pref,suff,cnt,ans;
long long delivery(int N, int K, int L, int p[]) {
n=N,k=K,l=L;
for (int i = 0; i < n; ++i) a[i+1]=p[i];
int lx=0,rx=n+1;
while (lx<rx-1) {
if (a[lx+1]<l-a[rx-1]+1) {
pos.push_back({a[++lx],0});
} else {
pos.push_back({a[--rx],1});
}
}
reverse(pos.begin(),pos.end());
suff=l+1;
for (auto i: pos) {
if (i.si==0) {
pref=i.fi;
} else {
suff=i.fi;
}
++cnt;
if (cnt==k) {
if (pref+l-suff+1<=l/2) ans += 2*(pref+l-suff+1);
else ans += l;
cnt=0; pref=0; suff=l+1;
}
}
if (cnt) {
if (pref+l-suff+1<=l/2) ans += 2*(pref+l-suff+1);
else ans += l;
}
return ans;
}
# | 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... |