Submission #784985

#TimeUsernameProblemLanguageResultExecution timeMemory
784985GusterGoose27Shortcut (IOI16_shortcut)C++17
71 / 100
2091 ms3756 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 inv[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) { vector<ll> mx(4, -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] && inv[v] < j) ? lval.second : lval.first; ll rv = (rval.first == d[v]-pre[v] && inv[v] < j) ? rval.second : rval.first; sum = inf; mx[0] = max(mx[0], c+d[v]-pre[v]+rv); mx[1] = max(mx[1], c+d[v]-pre[v]+lv); mx[2] = max(mx[2], c+d[v]+pre[v]+rv); mx[3] = max(mx[3], c+d[v]+pre[v]+lv); } for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { bool f = 1; for (int num = 0; num < 4; num++) { if (cur < mx[num]+((num&1) ? -pre[j] : pre[j]) + ((num >= 2) ? -pre[i] : pre[i])) f = 0; } if (f) 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>()); for (int i = 0; i < n; i++) inv[elems2[i].second] = i; // 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(47, d, c); while (mx > mn+1) { ll cur = (mn+mx)/2; if (makeable(cur, d, c)) mx = cur; else mn = cur; } return mx; }

Compilation message (stderr)

shortcut.cpp: In function 'bool makeable(ll, std::vector<int>, int)':
shortcut.cpp:38:8: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   38 |     ll sum = 0;
      |        ^~~
#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...