# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151948 | erebos | Boxes with souvenirs (IOI15_boxes) | C++17 | 2 ms | 508 KiB |
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 int;
int n;
inline int tozero(int idx) {
return min(idx, n-idx);
}
long long delivery(int N, int K, int L, int p[]) {
n=N;
ll ans=0;
for(int i=0; i<n; ++i) {
if(p[i]>=K) {
ans+=(p[i]/K)*(tozero(i)*2);
p[i]%=K;
}
}
int s, e=-1, i_have=K;
for(int i=0; i<n; ++i) {
if(p[i]) {
if(i_have==K) {
s=i;
} else if(i_have>p[i]) {
i_have-=p[i];
e=i;
} else if(i_have==p[i]) {
i_have=K;
ans+=tozero(s)+tozero(i);
e=-1;
} else {
s=i;
i_have=i_have+K-(p[i]);
ans+=tozero(s)+tozero(i);
e=-1;
}
}
}
if(e!=-1) {
ans+=tozero(e);
}
return ans;
}
Compilation message (stderr)
# | 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... |