제출 #606706

#제출 시각아이디문제언어결과실행 시간메모리
606706yuto1115선물상자 (IOI15_boxes)C++17
50 / 100
2039 ms23936 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)) { chmax(mx, a[i] + b[j] - ll(i + j + k - 1) / k * l); } //// 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); // } // } return ans - mx; }
#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...