제출 #831892

#제출 시각아이디문제언어결과실행 시간메모리
831892KerimShortcut (IOI16_shortcut)C++17
0 / 100
0 ms212 KiB
#include "shortcut.h" #include "bits/stdc++.h" #define ll long long using namespace std; //x+y, y-x (45 degrees rotation) //|x-xx|+|y-yy| -> max(|x-xx|, |y-yy|) const ll INF = 1e18; vector<ll> id; int get_id(ll x){ return 1 + int(lower_bound(id.begin(), id.end(), x) - id.begin()); } bool check(ll k, vector<int> &d, int c, vector<ll>&p){ int n = d.size(); ll X = -INF, Y = -INF; ll XX = INF, YY = INF; for (int j = 0; j < n; j++){ int b = get_id(-d[j] - p[j]); for (int i = 0; i < j; i++){ int a = get_id(d[i] - p[i] - k + 1); if (a > b){ X = max(X, p[i] + p[j] - (k - c - d[i] - d[j])); Y = max(Y, -p[i] + p[j] - (k - c - d[i] - d[j])); XX = min(XX, p[i] + p[j] + (k - c - d[i] - d[j])); YY = min(YY, -p[i] + p[j] + (k - c - d[i] - d[j])); } } } if (X > XX or Y > YY) return 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++){ ll x = p[i] + p[j], y = p[j] - p[i]; if (X <= x and x <= XX and Y <= y and y <= YY) return 1; } return 0; } ll find_shortcut(int n, vector<int> l, vector<int> d, int c){ vector<ll> p(n); for (int i = 0; i < n-1; i++) p[i+1] = p[i] + l[i]; for (int j = 0; j < n; j++) id.push_back(- d[j] - p[j]); sort(id.begin(), id.end()); id.erase(unique(id.begin(), id.end()), id.end()); ll st = 0, en = INF; while (st < en){ ll mid = (st+en) >> 1; if (check(mid, d, c, p)) en = mid; else st = mid + 1; } return st; }
#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...