이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of God
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 1e7 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll dp1[maxn], dp2[maxn], mn[maxn];
long long delivery(int n, int k, int l, int p[]) {
ll L = l;
for(ll i = 0; i < k; i++){
dp1[i] = p[i] * 2;
dp2[n - 1 - i] = (L - p[n - 1 - i]) * 2;
}
for(ll i = k; i < n; i++){
dp1[i] = dp1[i - k] + p[i] * 2;
dp2[n - 1 - i] = dp2[n - 1 - i + k] + (L - p[n - 1 - i]) * 2;
}
fill(mn, mn + k, inf);
ll mnn = inf;
ll ans = min(dp1[n - 1], dp2[0]);
ans = min(ans, L * ((n + k - 1) / k));
ll p1 = 0, p2 = k - 1;
for(ll i = 0; i < n; i++){
ans = min(ans, L * ((i - 1) / k) + mn[p2] + dp2[i]);
ans = min(ans, L * ((i - 1) / k) + mnn + dp2[i] + L);
mn[p1] = min(mn[p1], dp1[i] - L * (i / k));
mnn = min(mnn, mn[p1]);
p1++;
if(p1 == k) p1 = 0;
p2++;
if(p2 == k) p2 = 0;
}
return ans;
}
/*int main(){
int n, k, L, p[100];
cin >> n >> k >> L;
for(ll i = 0; i < n; i++){
cin >> p[i];
}
cout << "ans : " << delivery(n, k, L, p) << "\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... |