제출 #720990

#제출 시각아이디문제언어결과실행 시간메모리
720990joelgun14선물상자 (IOI15_boxes)C++17
20 / 100
1 ms308 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int N, int K, int L, int p[]) { long long pref[N + 1], suff[N + 2]; memset(pref, 0, sizeof(pref)); memset(suff, 0, sizeof(suff)); // coba ke next atau ke 0 for(int i = 0; i < N; ++i) { if(i % K == 0) { // ambil dr posisi sebelumnya itu sum, dengan distance sekarang if(i != 0) pref[i] += min(p[i - 1], L - p[i - 1]); pref[i + 1] = pref[i] + p[i]; } else { pref[i + 1] = pref[i] + p[i] - p[i - 1]; pref[i] += min(p[i - 1], L - p[i - 1]); } } for(int i = N - 1; i >= 0; --i) { if(i % K == (N - 1) % K) { if(i != N - 1) suff[i + 2] += min(L - p[i + 1], p[i + 1]); suff[i + 1] = suff[i + 2] + L - p[i]; } else { suff[i + 1] = suff[i + 2] + p[i + 1] - p[i]; suff[i + 2] += min(L - p[i + 1], p[i + 1]); } } pref[N] += min(p[N - 1], L - p[N - 1]); suff[1] += min(p[0], L - p[0]); long long mn = 1e18; for(int i = 0; i <= N; ++i) { //cout << pref[i] << " " << suff[i + 1] << endl; mn = min(mn, pref[i] + suff[i + 1]); } return mn; }
#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...