제출 #707433

#제출 시각아이디문제언어결과실행 시간메모리
707433tht2005선물상자 (IOI15_boxes)C++17
100 / 100
750 ms240236 KiB
#include <bits/stdc++.h> using namespace std; #define LL long long const LL INF = 1LL << 60; LL delivery(int N, int K, int L, int pos[]) { vector<LL> f(N + 1), val(N + 1); f[0] = 0; val[0] = -2LL * pos[0]; deque<LL> dq; for(int i = 1; i <= N; ++i) { f[i] = pos[i - 1] + min(pos[i - 1], L - pos[i - 1]) + (i < K ? 0 : f[i - K]); f[i] = min(f[i], L + (i < K ? 0 : f[i - K])); while(!dq.empty() && val[i - 1] < dq.back()) { dq.pop_back(); } dq.push_back(val[i - 1]); f[i] = min(f[i], 2LL * L + dq.front()); if(i < N) { val[i] = f[i] - 2LL * pos[i]; } if(i >= K && val[i - K] == dq.front()) { dq.pop_front(); } } return f[N]; } #ifdef tomoshibi int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k, l, pos[100]; cin >> n >> k >> l; for(int i = 0; i < n; ++i) { cin >> pos[i]; } cout << delivery(n, k, l, pos); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...