Submission #1022103

#TimeUsernameProblemLanguageResultExecution timeMemory
1022103AmirAli_H1Shortcut (IOI16_shortcut)C++17
0 / 100
1 ms452 KiB
// In the name of Allah #include <bits/stdc++.h> #include "shortcut.h" using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1e6 + 4; const ll oo = 1e18 + 4; int n; ll w; ll l[maxn], d[maxn]; ll D[maxn], ans; ll get_dis(int i, int j) { if (i > j) swap(i, j); return D[j] - D[i]; } ll getD(int u, int v) { ll x = 0; for (int i = 0; i < n; i++) { x = max(x, d[i]); for (int j = i + 1; j < n; j++) { x = max(x, min({get_dis(i, j), get_dis(i, u) + w + get_dis(v, j), get_dis(i, v) + w + get_dis(u, j)}) + d[i] + d[j]); } } return x; } void solve(int l, int r, int lx, int rx) { if (r - l <= 0) return ; int mid = (l + r) / 2; int j = mid; ll res = oo; int k = -1; for (int i = lx; i < min(rx, j + 1); i++) { ll x = getD(i, j); if (x < res) { res = x; k = i; } } ans = min(ans, res); solve(l, mid, lx, k + 1); solve(mid + 1, r, k, rx); } ll find_shortcut(int nx, vector<int> lx, vector<int> dx, int wx) { n = nx; w = wx; for (int i = 0; i < n - 1; i++) l[i] = lx[i]; for (int i = 0; i < n; i++) d[i] = dx[i]; D[0] = 0; for (int i = 1; i < n; i++) D[i] = D[i - 1] + l[i - 1]; ans = oo; solve(0, n, 0, n); 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...