Submission #606649

#TimeUsernameProblemLanguageResultExecution timeMemory
606649yuto1115Boxes with souvenirs (IOI15_boxes)C++17
35 / 100
1 ms256 KiB
#include "boxes.h" #include "bits/stdc++.h" #define rep(i, n) for(ll i = 0; i < ll(n); ++i) #define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i) #define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i) #define pb push_back #define eb emplace_back #define all(a) a.begin(),a.end() #define SZ(a) int(a.size()) using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vp = vector<P>; using vvp = vector<vp>; using vb = vector<bool>; using vvb = vector<vb>; using vs = vector<string>; const int inf = 1001001001; const ll linf = 1001001001001001001; template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll delivery(int n, int k, int l, int p[]) { vl a, b; a.pb(0); rep(i, n) { if (p[i] <= l / 2) a.pb(p[i]); else b.pb(l - p[i]); } b.pb(0); reverse(all(b)); rep(i, SZ(a)) { a[i] *= 2; if (i >= k) a[i] += a[i - k]; } rep(i, SZ(b)) { b[i] *= 2; if (i >= k) b[i] += b[i - k]; } ll ans = a.back() + b.back(); // ll mx = ans - ll(n + k - 1) / k * l; ll mx = 0; for (ll &i: a) i = a.back() - i; for (ll &i: b) i = b.back() - i; reverse(all(a)); reverse(all(b)); // rep(i, SZ(a) - 2 * k) assert(a[i + k] - a[i] >= a[i + 2 * k] - a[i + k]); // rep(i, SZ(b) - 2 * k) assert(b[i + k] - b[i] >= b[i + 2 * k] - b[i + k]); rep(sa, k + 1) { int sb = k - sa; if (sa >= SZ(a) or sb >= SZ(b)) continue; ll now = a[sa] + b[sb] - l; chmax(mx, now); while (sa + k < SZ(a) or sb + k < SZ(b)) { if (sa + k < SZ(a) and sb + k < SZ(b)) { if (a[sa + k] - a[sa] > b[sb + k] - b[sb]) { now += a[sa + k] - a[sa] - l; sa += k; } else { now += b[sb + k] - b[sb] - l; sb += k; } } else if (sa + k < SZ(a)) { now += a[sa + k] - a[sa] - l; sa += k; } else { now += b[sb + k] - b[sb] - l; sb += k; } chmax(mx, now); } } chmax(mx, ans - ll(n + k - 1) / k * l); return ans - mx; // return min(ans - mx, ll(n + k - 1) / k * l); }

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:70:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   70 |         int sb = k - sa;
      |                  ~~^~~~
#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...