제출 #24585

#제출 시각아이디문제언어결과실행 시간메모리
24585gs14004Shortcut (IOI16_shortcut)C++11
0 / 100
2000 ms17648 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<lint, lint> pi; int n, c; lint a[1000005], b[1000005]; bool trial(lint x){ lint ps = -1e18, pe = 1e18, ms = -1e18, me = 1e18; lint mxp = -1e18, mnp = 1e18, mxm = -1e18, mnm = 1e18; vector<pi> v, w; for(int i=0; i<n; i++) v.push_back(pi(a[i] + b[i], i)); for(int i=0; i<n; i++) w.push_back(pi(x + -a[i] + b[i], i)); sort(v.begin(), v.end()); sort(w.begin(), w.end()); int p = 0; for(int i=0; i<n; i++){ while(p < n && w[p].first < v[i].first){ mxp = max(mxp, a[w[p].second] + b[w[p].second]); mxm = max(mxm, -a[w[p].second] + b[w[p].second]); mnp = min(mnp, a[w[p].second] + b[w[p].second]); mnm = min(mnm, -a[w[p].second] + b[w[p].second]); } ps = max(ps, mxp - x + c + b[v[i].second] + a[v[i].second]); pe = min(pe, mnm + x - c + b[v[i].second] - a[v[i].second]); ms = max(ms, mxp - x + c - b[v[i].second] + a[v[i].second]); me = min(me, mnm + x - c - b[v[i].second] - a[v[i].second]); } /* for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ if(b[j] + a[j] > x + b[i] - a[i]){ lint r = x - c - a[i] - a[j]; ps = max(ps, b[i] + a[i] - x + c + b[j] + a[j]); pe = min(pe, b[i] - a[i] + x - c + b[j] - a[j]); ms = max(ms, b[i] + a[i] - x + c - b[j] + a[j]); me = min(me, b[i] - a[i] + x - c - b[j] - a[j]); } } }*/ for(int i=0; i<n; i++){ lint s = max(ps - b[i], b[i] - me); lint e = min(pe - b[i], b[i] - ms); if(s <= e && upper_bound(b, b+n, e) != lower_bound(b, b+n, s)) return true; } return false; } long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) { ::n = n; ::c = c; for(int i=0; i<n; i++){ a[i] = d[i]; if(i >= 1) b[i] = b[i-1] + l[i-1]; } lint s = 0, e = 1e16; while(s != e){ lint m = (s+e)/2; if(trial(m)) e = m; else s = m+1; } return s; }
#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...