Submission #621044

#TimeUsernameProblemLanguageResultExecution timeMemory
621044Sergio_2357Boxes with souvenirs (IOI15_boxes)C++17
20 / 100
1 ms212 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; #define int long long #define nint signed typedef vector<int> vi; int delivery2(nint N, nint K, nint L, nint P[], bool tryp) { //cout << "HELLO " << tryp << endl; int n = N; int k = K; int l = L; vi p(n); for (int i = 0; i < n; i++) p[i] = P[i]; vi d1(n + 1), d2(n + 1); for (int i = 1; i <= n; i++) d1[i] = p[i - 1]; for (int i = 1; i <= n; i++) d2[i] = l - p[n - i]; //for (int x : d1) // cout << x << ' '; //cout << endl; //for (int x : d2) // cout << x << ' '; //cout << endl; int rem = n; int a1, a2; a1 = a2 = 0; bool fst = true; int res = 0; while (rem) { int re = min(k, rem); int p1 = min(2 * d1[re + a1], l); int p2 = min(2 * d2[re + a2], l); int ch = 1e18; int cp1 = 0; int cp2 = 0; if (p1 < p2) { ch = p1; cp1 = re; } else { ch = p2; cp2 = re; } if (fst && tryp) { ch = 1e18; for (int i = 1; i < re; i++) { int th = (2 * d1[i + a1]) + (2 * d2[re - i + a2]); if (th < ch) { ch = th; cp1 = i; cp2 = re - i; } } } rem -= re; fst = false; res += ch; a1 += cp1; a2 += cp2; } return res; } int delivery(nint N, nint K, nint L, nint P[]) { return min(delivery2(N, K, L, P, false), delivery2(N, K, L, P, true)); }
#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...