제출 #593659

#제출 시각아이디문제언어결과실행 시간메모리
593659davi_bart선물상자 (IOI15_boxes)C++17
50 / 100
2004 ms23076 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include "boxes.h" #define ll long long #define fi first #define se second #define pb push_back #define int ll using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> v; int N, K, L; int dist(int a, int b) { if (a > b) swap(a, b); return min(b - a, a + L - b); } long long delivery(signed n, signed k, signed l, signed p[]) { N = n; K = k; L = l; for (int i = 0; i < N; i++) v.pb(p[i]); vector<int> ans; for (int i = 0; i <= N; i++) { int tot = 0; for (int j = i - 1; j >= 0; j -= K) { tot += dist(0, v[j]); for (int h = j - 1; h >= max((int)0, j - K + 1); h--) { tot += dist(v[h + 1], v[h]); } int o = v[0]; if (j - K + 1 >= 0) o = v[j - K + 1]; tot += dist(0, o); } ans.pb(tot); // cout << tot << " "; } // cout << endl; reverse(v.begin(), v.end()); vector<int> ans1; for (int i = 0; i <= N; i++) { int tot = 0; for (int j = i - 1; j >= 0; j -= K) { tot += dist(0, v[j]); for (int h = j - 1; h >= max((int)0, j - K + 1); h--) { tot += dist(v[h + 1], v[h]); } int o = v[0]; if (j - K + 1 >= 0) o = v[j - K + 1]; tot += dist(0, o); } ans1.pb(tot); // cout << tot << " "; } // cout << endl; int mi = 1e18; for (int i = 0; i <= N; i++) { // cout << ans[i] << " " << ans1[N - i] << endl; mi = min(mi, ans[i] + ans1[N - i]); } return mi; }
#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...