# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
219610 | summitwei | Boxes with souvenirs (IOI15_boxes) | C++17 | 5 ms | 384 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 <bits/stdc++.h>
#include <boxes.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)
#define MN 10000005
int n, k; ll l;
ll d[MN];
ll ps[MN];
ll rps[MN];
ll delivery(int n, int k, int l, int positions[]){
::n = n; ::k = k; ::l = (ll)l;
F0R(i, n) d[i] = positions[i];
F0R(i, n){
ps[i] = d[i]*2;
if(i >= k){
ps[i] += ps[i-k];
}
}
RFOR(i, n-1, 0){
rps[i] = (l-d[i])*2;
if(i+k < n){
rps[i] += rps[i+k];
}
}
ll ans = INF;
F0R(i, n-1){
ans = min(ans, ps[i]+rps[i+1]);
}
if(k >= n) ans = min(ans, ::l);
else{
F0R(i, n-k+1){
int lf = i-1, rt = i+k;
ll res = ::l+(lf<0?0:ps[lf])+(rt>=n?0:rps[rt]);
ans = min(ans, res);
}
}
return ans;
}
/*int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(0);
int N, K, L;
cin >> N >> K >> L;
int pos[N];
F0R(i, N) cin >> pos[i];
cout << delivery(N, K, L, pos) << "\n";
return 0;
}*/
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... |