제출 #729047

#제출 시각아이디문제언어결과실행 시간메모리
729047kirakaminski968선물상자 (IOI15_boxes)C++17
100 / 100
661 ms372244 KiB
#include <bits/stdc++.h> using namespace std; long long delivery(int N, int K, int L, int positions[]){ long long ans = 0; vector<long long> p; p.push_back(0); for(int i = 0;i<N;++i) p.push_back(positions[i]); long long pref[N + 2], suf[N + 2]; pref[0] = suf[N+1] = 0; for(int i = 1;i <= N;++i) { pref[i] = (i<=K) ? p[i] * 2LL : p[i] * 2LL + pref[i - K]; } for(int i = N;i>=1;--i) { suf[i] =(i+K-1>N) ? (L-p[i]) * 2LL : (L-p[i]) * 2LL + suf[i+K]; } ans = suf[1]; for(int i = 0; i <= N; i++) { ans = min(ans,pref[i] + suf[i + 1]); if(i+K <= N) ans = min(ans,pref[i]+L+suf[i + K + 1]); else ans = min(ans, pref[i] + L); } return ans; }
#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...