이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 1e7+7;
int a[MAXN], nArr, k, L;
#ifdef Nhoksocqt1
ll delivery(int _N, int _K, int _L, int _pos[]);
int _P[MAXN];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen("BOXES.inp", "r", stdin);
freopen("BOXES.out", "w", stdout);
int N, K, L;
cin >> N >> K >> L;
for (int i = 0; i < N; ++i) {
cin >> _P[i];
}
cout << delivery(N, K, L, _P) << '\n';
return 0;
}
#endif // Nhoksocqt1
ll delivery(int _N, int _K, int _L, int _pos[]) {
nArr = _N, k = _K, L = _L;
for (int i = 1; i <= nArr; ++i)
a[i] = _pos[i - 1];
ll result(0);
int l(1), r(nArr);
for (int i = 1; i <= nArr; ++i) {
if(2 * a[i] >= L)
break;
if(i % k == 0) {
result += 2 * a[i];
l = i + 1;
}
}
for (int i = nArr; i >= l; --i) {
if(2 * (L - a[i]) >= L)
break;
if((nArr - i + 1) % k == 0) {
result += 2 * (L - a[i]);
r = i - 1;
}
}
ll answer(1e18);
int last = min(k, r - l + 1);
for (int dem = 0; dem <= last; ++dem) {
int costLeft = (dem > 0 ? min(L, 2 * a[l + dem - 1]) : 0);
ll costRight = (dem <= r - l ? 1LL * (r - l + 1 - dem + k - 1) / k * L : 0LL);
answer = min(answer, result + costLeft + costRight);
}
return answer;
}
# | 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... |