Submission #241718

#TimeUsernameProblemLanguageResultExecution timeMemory
241718godwindShortcut (IOI16_shortcut)C++14
23 / 100
2094 ms4988 KiB
#include "shortcut.h" #include <iostream> #include <vector> #include <algorithm> #include <random> #include <set> #include <map> #include <queue> #include <cstring> #include <cmath> #include <bitset> #include <iomanip> #include <functional> using namespace std; const int N = 1000; const long long INF = 1e18 + 228; vector< pair<int, int> > g[N]; void AddEdge(int u, int v, int w) { g[u].emplace_back( v, w ); g[v].emplace_back( u, w ); } long long dist[N][N]; void dfs(int v, int st, long long DST = 0, int par = -1) { dist[v][st] = DST; for (auto go : g[v]) { int to = go.first; int w = go.second; if (to == par) continue; dfs(to, st, DST + w, v); } } mt19937 rnd(rand()); long long find_shortcut(int n, vector<int> l, vector<int> d, int c) { for (int i = 0; i < n - 1; ++i) { AddEdge(i, i + 1, l[i]); } for (int i = 0; i < n; ++i) { AddEdge(i, n + i, d[i]); } int V = 2 * n - 1; for (int i = 0; i < V; ++i) { dfs(i, i); } vector< pair<int, int> > ord; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ord.emplace_back( i , j ); } } shuffle( ord.begin(), ord.end(), rnd ); vector< pair<int, int> > ord2; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ord2.emplace_back( i, j ); } } sort( ord2.begin(), ord2.end(), [&] (pair<int, int> A, pair<int, int> B) { return dist[A.first][A.second] > dist[B.first][B.second]; }); long long best = INF; for (auto P : ord) { int A = P.first, B = P.second; long long cur_dia = 0; for (auto _p : ord2) { int i = _p.first, j = _p.second; long long cur = min({dist[i][j], dist[i][A] + c + dist[j][B], dist[i][B] + c + dist[j][A]}); cur = cur + d[i] + d[j]; cur_dia = max(cur_dia, cur); if (cur_dia >= best) { break; } } if (cur_dia < best) { best = cur_dia; } } return best; }
#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...