이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<long double, long double>
#define sz(x) (int)((x).size())
//#define int long long
#include "boxes.h"
ll delivery(int n, int k, int L, int pos[]){
ll dp1[n + 5], dp2[n + 5];
vector<int>pos2;
for(int i = 0; i < n; i++){
pos2.push_back(pos[i]);
}
reverse(all(pos2));
for(int i = 0; i < n; i++){
dp1[i] = (i < k ? 2ll*pos[i] : dp1[i - k] + 2ll*pos[i]);
}
for(int i = n - 1; i >= 0; i--){
dp2[i] = (i + k >= n ? 2ll*(L - pos[i]) : dp2[i + k] + 2ll*(L - pos[i]));
//cout << i << ' ' << (L - pos[i]) << '\n';
}
ll ans = min(dp2[0], dp1[n - 1]);
for(int i = 0; i < n - 1; i++){
ans = min(ans, dp1[i] + dp2[i + 1]);
}
if(n <= k){
ans = min(ans, L*1ll);
return ans;
}
ans = min(ans, L*1ll + min(dp2[k], dp1[n - k - 1]));
//cout << "pos" << '\n';
//for(int i = 0; i < n; i++)cout << pos[i] << ' '; cout << '\n';
//cout << "dp1" << '\n';
//for(int i = 0; i < n; i++)cout << dp1[i] << ' '; cout << '\n';
//cout << "dp2" << '\n';
//for(int i = 0; i < n; i++)cout << dp2[i] << ' '; cout << '\n';
for(int i = 0; i < n; i++){
if(i + k + 1 >= n)continue;
ans = min(ans, dp1[i] + L + dp2[i + k + 1]);
}
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... |