Submission #1080669

#TimeUsernameProblemLanguageResultExecution timeMemory
1080669asdasdqwerShortcut (IOI16_shortcut)C++14
23 / 100
2047 ms444 KiB
#include <bits/stdc++.h> using namespace std; #include "shortcut.h" #define ll long long int #define pii array<ll, 2> #define tii array<ll,3> ll dijkstra(vector<vector<pii>> &g, int source, vector<int> &d) { int n=(int)g.size(); vector<ll> dis(n, (ll)1e16); dis[source]=d[source]; priority_queue<pii> pq; pq.push({-dis[source], source}); vector<bool> vis(n, false); while (!pq.empty()) { auto [d, node] = pq.top();pq.pop(); if (vis[node]) continue; vis[node]=true; for (auto [ne, we] : g[node]) { if ((dis[node] + we) < dis[ne]) { dis[ne] = dis[node] + we; pq.push({-dis[ne], ne}); } } } ll mx = 0; for (int i=0;i<n;i++) { if (i == source) continue; mx = max(mx, dis[i] + (ll)d[i]); } return mx; } ll diameter(vector<vector<pii>> &g, vector<int> &d) { ll dis = 0; for (int i=0;i<(int)g.size();i++) { dis = max(dis, dijkstra(g, i, d)); } return dis; } long long find_shortcut(int n, std::vector <int> l, std::vector <int> d, int c) { int tmp = n; for (int i=0;i<n;i++)if (d[i]) tmp++; vector<vector<pii>> g(n); for (int i=0;i<n-1;i++) { g[i].push_back({i+1, (ll)l[i]}); g[i+1].push_back({i, (ll)l[i]}); } ll mxDis = 1e16; for (int i=0;i<n;i++) { for (int j=i+1;j<n;j++) { g[i].push_back({j, (ll)c}); g[j].push_back({i, (ll)c}); mxDis = min(mxDis, diameter(g, d)); g[i].pop_back(); g[j].pop_back(); } } return mxDis; } // long long find_shortcut(int n, std::vector <int> l, std::vector <int> d, int c) { // int tmp = n; // for (int i=0;i<n;i++)if (d[i]) tmp++; // vector<vector<pii>> g(tmp); // for (int i=0;i<n-1;i++) { // g[i].push_back({i+1, (ll)l[i]}); // g[i+1].push_back({i, (ll)l[i]}); // } // int lst = n; // vector<int> child(n, -1), parent(n, -1); // for (int i=0;i<n;i++) { // if (d[i] == 0) continue; // g[i].push_back({lst, (ll)d[i]}); // g[lst].push_back({i, (ll)d[i]}); // child[i] = lst; // parent[lst-n] = i; // lst++; // } // // get diameter pair // tii pr = diameter(g); // // cout << pr[0]-n << " " << pr[1]-n << "\n"; // // cout << pr[2] << "\n"; // for (int i=0;i<2;i++) { // if (pr[i] >= n) pr[i] = parent[pr[i]-n]; // } // // cout << pr[0] << " " << pr[1] << "\n"; // vector<ll> al = {0, n-1, pr[0], pr[1]}; // sort(al.begin(), al.end()); // al.erase(unique(al.begin(), al.end()), al.end()); // ll diam = pr[2]; // for (int i=0;i<(int)al.size();i++) { // for (int j=0;j<n;j++) { // if (j == al[i]) continue; // g[al[i]].push_back({j, c}); // g[j].push_back({al[i], c}); // diam = min(diam, diameter(g)[2]); // g[al[i]].pop_back();g[j].pop_back(); // } // } // return diam; // }

Compilation message (stderr)

shortcut.cpp: In function 'long long int dijkstra(std::vector<std::vector<std::array<long long int, 2> > >&, int, std::vector<int>&)':
shortcut.cpp:18:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |         auto [d, node] = pq.top();pq.pop();
      |              ^
shortcut.cpp:22:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |         for (auto [ne, we] : g[node]) {
      |                   ^
#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...