Submission #1182430

#TimeUsernameProblemLanguageResultExecution timeMemory
1182430trvhungBoxes with souvenirs (IOI15_boxes)C++20
10 / 100
0 ms328 KiB
#include "boxes.h" #include <bits/stdc++.h> // #include <ext/rope> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // using namespace __gnu_cxx; using namespace std; // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define bit(mask, i) ((mask >> i) & 1) #define el '\n' #define F first #define S second template <class X, class Y> bool maximize(X &x, const Y &y) { return (x < y ? x = y, 1 : 0); } template <class X, class Y> bool minimize(X &x, const Y &y) { return (x > y ? x = y, 1 : 0); } const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1e9 + 7; const int MULTI = 0; const ld eps = 1e-9; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // R D L U const int ddx[4] = {-1, 1, 1, -1}, ddy[4] = {1, 1, -1, -1}; // UR DR DL UL const char cx[4] = {'R', 'D', 'L', 'U'}; const ll base = 31; const int nMOD = 2; const ll mods[] = {(ll)1e9 + 10777, (ll)1e9 + 19777, (ll)1e9 + 3, (ll)1e9 + 3777}; const int maxn = 1e7 + 5; int n, k, l, pos[maxn]; ll res; int dist(int u, int v) { if (u > v) swap(u, v); return min(v - u, u + l - v); } int calc(int le, int ri) { return min(pos[ri] + dist(0, pos[ri]), l - pos[le] + dist(0, pos[le])); } void solve() { int ptl = 0, ptr = n - 1; while (1) if (ptl + k - 1 < ptr - k + 1) { if (calc(ptl, ptl + k - 1) < calc(ptr - k + 1, ptr)) res += calc(ptl, ptl + k - 1), ptl += k; else res += calc(ptr - k + 1, ptr), ptr -= k; } else { if (calc(ptl, ptl + k - 1) < calc(ptr - k + 1, ptr)) res += calc(ptl, ptl + k - 1), ptl += k; else res += calc(ptr - k + 1, ptr), ptr -= k; if (ptl <= ptr) res += calc(ptl, ptr); break; } } ll delivery(int N, int K, int L, int p[]) { n = N; k = K; l = L; for (int i = 0; i < n; ++i) pos[i] = p[i]; solve(); return res; }
#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...