Submission #1020514

#TimeUsernameProblemLanguageResultExecution timeMemory
1020514vjudge1Shortcut (IOI16_shortcut)C++17
0 / 100
2086 ms2740 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define rall(s) s.rbegin(), s.rend() #define all(s) s.begin(), s.end() #define sz(s) (int)s.size() #define s second #define f first using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const ll inf = 1e18, N = 1e5; vector<pll> g[N]; pll fnd(int x, int n) { priority_queue<pll> s; vector<ll> d(n, inf); d[x] = 0; s.push({0, x}); int mx = x; while (sz(s)) { auto [dt, u] = s.top(); s.pop(); if (-dt != d[u]) continue; if (d[u] > d[mx]) mx = u; for (auto [to, w]: g[u]) { if (d[to] > d[u] + w) { d[to] = d[u] + w; s.push({-d[to], to}); } } } return {mx, d[mx]}; } ll f(int n) { ll res = 0; for (int i = 0; i < n; i++) { res = max(res, fnd(i, n).s); } return res; } long long find_shortcut(int n, vector<int> l, vector<int> d, int c) { for (int i = 0; i < n - 1; i++) { g[i].push_back({i + 1, l[i]}); g[i + 1].push_back({i, l[i]}); } for (int i = 0; i < n; i++) { g[i].push_back({i + n, d[i]}); g[i + n].push_back({i, d[i]}); } ll ans = inf; for (int x = 0; x < n; x++) { for (int y = x + 1; y < n; y++) { g[x].push_back({y, c}); g[y].push_back({x, c}); ans = min(ans, f(2 * n)); g[x].pop_back(); g[y].pop_back(); } } 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...