Submission #567539

#TimeUsernameProblemLanguageResultExecution timeMemory
567539ngpin04Boxes with souvenirs (IOI15_boxes)C++17
10 / 100
1 ms340 KiB
#include <bits/stdc++.h> #include "boxes.h" #define fi first #define se second #define mp make_pair #define TASK "" #define bit(x) (1LL << (x)) #define getbit(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rd() % (r - l + 1); } const int N = 1e6 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); int pre[N]; int suf[N]; int a[N]; int n,k,l; long long solve() { sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) pre[i] = 2 * a[i] + pre[max(0, i - k)]; for (int i = n; i >= 1; i--) suf[i] = 2 * (l - a[i]) + suf[min(n + 1, i + k)]; // for (int i = 1; i <= n; i++) // cerr << pre[i] << " " << suf[i] << "\n"; long long ans = 1LL * ((n + k - 1) / k) * l; for (int t = 0; t * k < n; t++) { int lef = n - t * k; int lo = 0; int hi = lef + 1; while (hi - lo > 1) { int mid = (lo + hi) >> 1; int l = mid; int r = lef - mid; if (pre[l] < suf[n - r + 1]) lo = mid; else hi = mid; } mini(hi, lef); for (int i = lo; i <= hi; i++) { int x = i; int y = lef - i; mini(ans, 1LL * t * l + pre[x] + suf[n - y + 1]); } } return ans; } long long delivery(int N, int K, int L, int p[]) { n = N; k = K; l = L; for (int i = 0; i < n; i++) a[i + 1] = p[i]; return solve(); } //#include "grader.cpp"

Compilation message (stderr)

boxes.cpp: In function 'int rand(int, int)':
boxes.cpp:20:14: warning: conversion from 'std::mersenne_twister_engine<long unsigned int, 64, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>::result_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   20 |     return l + rd() % (r - l + 1);
      |            ~~^~~~~~~~~~~~~~~~~~~~
boxes.cpp: In function 'long long int solve()':
boxes.cpp:51:17: warning: declaration of 'l' shadows a global declaration [-Wshadow]
   51 |             int l = mid;
      |                 ^
boxes.cpp:31:9: note: shadowed declaration is here
   31 | int n,k,l;
      |         ^
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:68:24: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   68 | long long delivery(int N, int K, int L, int p[]) {
      |                    ~~~~^
boxes.cpp:22:11: note: shadowed declaration is here
   22 | const int N = 1e6 + 5;
      |           ^
#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...