제출 #838021

#제출 시각아이디문제언어결과실행 시간메모리
838021pavementShortcut (IOI16_shortcut)C++17
71 / 100
2041 ms1748 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define mp make_pair using ll = long long; ll find_shortcut(int n, vector<int> l, vector<int> d, int c) { vector<ll> x(n, 0); for (int i = 0; i + 1 < n; i++) { x[i + 1] = x[i] + (ll)l[i]; } auto good = [&](ll k) { ll min_x = LLONG_MIN, max_x = LLONG_MAX, min_y = LLONG_MIN, max_y = LLONG_MAX; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if ((ll)d[i] + (ll)d[j] + x[j] - x[i] > k) { ll v = k - (ll)c - (ll)d[i] - (ll)d[j]; pair<ll, ll> lower_left = mp(x[i] - v - x[j], x[i] - v + x[j]); pair<ll, ll> upper_right = mp(x[i] + v - x[j], x[i] + v + x[j]); min_x = max(min_x, lower_left.first); max_x = min(max_x, upper_right.first); min_y = max(min_y, lower_left.second); max_y = min(max_y, upper_right.second); } } } if (min_x <= max_x && min_y <= max_y) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (min_x <= x[i] - x[j] && x[i] - x[j] <= max_x && min_y <= x[i] + x[j] && x[i] + x[j] <= max_y) { return true; } } } return false; } else { return false; } }; ll lo = 0, hi = (ll)1e16, ans = -1; while (lo <= hi) { ll mid = (lo + hi) / 2ll; if (good(mid)) { ans = mid; hi = mid - 1; } else { lo = mid + 1; } } return ans; }
#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...