Submission #1010050

#TimeUsernameProblemLanguageResultExecution timeMemory
1010050overwatch9Shortcut (IOI16_shortcut)C++17
0 / 100
1 ms348 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector <vector <pair <int, int>>> adj; int N; pair <int, ll> dijkstra(int s) { priority_queue <pair <ll, int>> pq; vector <ll> dis(N+1, 1e17); vector <bool> processed(N+1); dis[s] = 0; pq.push({0, s}); int node = 0, mx = 0; while (!pq.empty()) { s = pq.top().second; pq.pop(); if (processed[s]) continue; processed[s] = true; if (mx < dis[s]) { mx = dis[s]; node = s; } for (auto i : adj[s]) { if (dis[i.first] > dis[s] + i.second) { dis[i.first] = dis[s] + i.second; pq.push({-dis[i.first], i.first}); } } } return {node, mx}; } long long find_shortcut(int n, vector<int> l, vector<int> d, int c) { adj.resize(n * 2 + 5); for (int i = 0; i+1 < n; i++) { adj[i].push_back({i+1, l[i]}); adj[i+1].push_back({i, l[i]}); } int ogn = n; for (int i = 0; i < ogn; i++) { if (d[i] == 0) continue; adj[i].push_back({n, d[i]}); adj[n].push_back({i, d[i]}); n++; } N = n; pair <int, ll> res = dijkstra(0); res = dijkstra(res.first); ll ans = res.second; for (int i = 0; i < ogn; i++) { for (int j = i+1; j < ogn; j++) { adj[i].push_back({j, c}); adj[j].push_back({i, c}); res = dijkstra(0); res = dijkstra(res.first); ans = min(ans, res.second); adj[i].pop_back(); adj[j].pop_back(); } } return ans; } // int main() { // int n; // cin >> n; // vector <int> l(n), d(n); // for (int i = 0; i < n-1; i++) // cin >> l[i]; // for (int i = 0; i < n; i++) // cin >> d[i]; // int c; // cin >> c; // cout << find_shortcut(n, l, d, c) << '\n'; // }
#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...