Submission #606752

#TimeUsernameProblemLanguageResultExecution timeMemory
606752yuto1115Boxes with souvenirs (IOI15_boxes)C++17
35 / 100
1 ms284 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 = max(0LL, ans - ll(n + k - 1) / k * l); 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)) rep(j, SZ(b)) { // if ((i + j) % k) continue; // chmax(mx, a[i] + b[j] - ll(i + j + k - 1) / k * l); // } 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); // for (int i = sa; i < SZ(a); i += k) { // for (int j = sb; j < SZ(b); j += k) { // chmax(mx, now + a[i] - a[sa] + b[j] - b[sb] - ll(i + j - sa - sb) / k * l); // } // } vl x, y; while (sa + k < SZ(a)) { x.pb(a[sa + k] - a[sa] - l); sa += k; } while (sb + k < SZ(b)) { y.pb(b[sb + k] - b[sb] - l); sb += k; } rep(i, SZ(x) + 1) { ll tmp = now; for (ll j: y) { tmp += j; chmax(mx, tmp); } if (i < SZ(x)) now += x[i]; } // 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); // } } return ans - mx; }

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:71:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   71 |         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...