제출 #320369

#제출 시각아이디문제언어결과실행 시간메모리
320369nikatamliani선물상자 (IOI15_boxes)C++14
100 / 100
535 ms196656 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; long long delivery(int N, int K, int L, int positions[]) { long long p[N], s[N]; for(int i = 0; i < N; ++i) { p[i] = 2 * positions[i]; if(i >= K) { p[i] += p[i - K]; } } for(int i = N - 1; i >= 0; --i) { s[i] = 2 * (L - positions[i]); if(i + K < N) { s[i] += s[i + K]; } } long long answer = min(p[N - 1], s[0]); for(int i = 0; i < N - 1; ++i) { answer = min(answer, p[i] + s[i + 1]); } for(int start = 0; start + K - 1 < N; ++start) { int end = start + K - 1; long long left = (start > 0 ? p[start - 1] : 0); long long right = (end < N - 1 ? s[end + 1] : 0); long long middle = L; answer = min(answer, left + middle + right); } return answer; } // int main() { // int pos[] = {1, 2, 5}; // cout << delivery(3, 2, 8, pos) << '\n'; // }
#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...