Submission #784945

#TimeUsernameProblemLanguageResultExecution timeMemory
784945GusterGoose27Shortcut (IOI16_shortcut)C++17
0 / 100
1 ms212 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; const int MAXN = 1e5+5; const int MAXM = 1e9+5; const ll inf = (ll)MAXN*MAXM; ll pre[MAXN]; ll max_dist[MAXN]; pli elems1[MAXN]; pli elems2[MAXN]; int n; ll sum(int l, int r) { return pre[r]-pre[l]; } pll max(pll a, ll b) { if (b > a.first) return pll(b, a.first); if (b > a.second) return pll(a.first, b); return pll(a.first, a.second); } bool makeable(ll cur, vector<int> d, int c) { ll mx1 = -inf; ll mx2 = -inf; int j = 0; // priority_queue<int> left; // priority_queue<int, vector<int>, greater<int>> right; pll lval(-inf, -inf); pll rval(-inf, -inf); ll sum = 0; for (int i = 0; i < n; i++) { while (j < n && elems2[j].first > cur+elems1[i].first) { int v = elems2[j].second; lval = max(lval, pre[v]+d[v]); rval = max(rval, d[v]-pre[v]); j++; } int v = elems1[i].second; ll lv = (lval.first == pre[v]+d[v]) ? lval.second : lval.first; ll rv = (rval.first == d[v]-pre[v]) ? rval.second : rval.first; int mn = -1; // max val leq this int mx = n; while (mx > mn+1) { int split = (mn+mx)/2; if (2*pre[split] <= lv-rv) mn = split; else mx = split; } sum = inf; if (mn >= 0) sum = lv-pre[mn]; if (mx < n) sum = min(sum, rv+pre[mx]); mx1 = max(mx1, c+d[v]-pre[v]+sum); mx2 = max(mx2, c+d[v]+pre[v]+sum); // assert(mx2 < 140); } for (int i = 0; i < n; i++) { if (cur >= mx1+pre[i] && cur >= mx2-pre[i]) return 1; } return 0; } ll find_shortcut(int N, vector<int> l, vector<int> d, int c) { n = N; for (int i = 1; i < n; i++) pre[i] = pre[i-1]+l[i-1]; for (int i = 0; i < n; i++) { elems1[i] = pli(pre[i]-d[i], i); elems2[i] = pli(pre[i]+d[i], i); } sort(elems1, elems1+n, greater<pli>()); sort(elems2, elems2+n, greater<pli>()); // max_dist[n-1] = d[n-1]; // int split = n-1; // ll rdist = max_dist[n-1]; // ll ldist = 0; // for (int i = n-2; i >= 0; i--) { // ldist = max(ldist, d[i]+sum(i, split)); // while (split && ldist >= rdist+l[split-1]) { // split--; // ldist -= l[split]; // rdist += l[split]; // rdist = max(rdist, (ll)d[split]); // } // max_dist[i] = max(ldist, rdist); // } ll mn = 0; ll mx = inf; makeable(150, d, c); while (mx > mn+1) { ll cur = (mn+mx)/2; if (makeable(cur, d, c)) mx = cur; else mn = cur; } return 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...