제출 #567545

#제출 시각아이디문제언어결과실행 시간메모리
567545ngpin04선물상자 (IOI15_boxes)C++17
50 / 100
2051 ms33464 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); 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"; long long ans = 1LL * ((n + k - 1) / k) * l; for (int t = 0, lef = n; t * k < n; t++, lef -= k) for (int i = 0; i <= lef; 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"

컴파일 시 표준 에러 (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:55:24: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   55 | 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...