Submission #567548

#TimeUsernameProblemLanguageResultExecution timeMemory
567548ngpin04Boxes 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 = 1e7 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); long long best[N]; long long pre[N]; long long 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"; for (int i = 0; i < k; i++) best[i] = ooo; long long ans = 1LL * ((n + k - 1) / k) * l; for (int r = 1; r <= n; r++) { mini(best[r % k], pre[r] - (long long) (r / k) * l); mini(ans, best[r % k] + (long long) (r / k) * l + suf[r + 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 delivery(int, int, int, int*)':
boxes.cpp:57:24: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   57 | long long delivery(int N, int K, int L, int p[]) {
      |                    ~~~~^
boxes.cpp:22:11: note: shadowed declaration is here
   22 | const int N = 1e7 + 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...