Submission #1158949

#TimeUsernameProblemLanguageResultExecution timeMemory
1158949countlessCyberland (APIO23_cyberland)C++20
97 / 100
966 ms2162688 KiB
#include "cyberland.h" #include <vector> #include <queue> #include <iostream> #include <math.h> #include <tuple> using namespace std; typedef long long ll; typedef long double ld; const ld INF = 9e18; // this should work for k <= 30 ld divByPow2(ll x, ll k) { return (ld)x / (ld)pow(2, k); } // pretty sure this works too void checkReal(int start, int H, vector<vector<pair<ll, ll>>> &adj, vector<bool> &real) { real[start] = true; if (start == H) return; for (const pair<ll, ll> &i : adj[start]) { if (!real[i.first]) { checkReal(i.first, H, adj, real); } } } double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {\ vector<vector<pair<ll, ll>>> adj(N+5); cerr << "arr: "; for (int i = 0; i < N; i++) { cerr << arr[i] << " "; } cerr << endl; for (int i = 0; i < M; i++) { adj[x[i]].push_back({y[i], c[i]}); adj[y[i]].push_back({x[i], c[i]}); } vector<bool> real(N+5, false); checkReal(0, H, adj, real); if (!real[H]) return -1; real[H] = false; vector<vector<ld>> dist(N+5, vector<ld>(K + 1 + 5, INF)); dist[H][0] = 0; priority_queue<tuple<ld, ll, ll>, vector<tuple<ld, ll, ll>>, greater<tuple<ld, ll, ll>>> pq; pq.push(make_tuple((ld)0.0, 0LL, (ll)H)); while (!pq.empty()) { // const auto [cdist, k, node] = pq.top(); ld cdist = get<0>(pq.top()); ll k = get<1>(pq.top()); ll node = get<2>(pq.top()); pq.pop(); if (cdist > dist[node][k]) continue; if ((arr[node] == 0 || node == 0) && real[node]) { return cdist; } // if (cdist != dist[node][k]) continue; for (const pair<ll, ll> &i : adj[node]) { if (i.first == H) continue; if (!real[i.first]) continue; ld ndist1 = cdist + ((ld)i.second / (ld)pow(2.0, (ld)k)); if (ndist1 < dist[i.first][k]) { dist[i.first][k] = ndist1; pq.push(make_tuple(dist[i.first][k], k, i.first)); } if (arr[node] == 2 && k < K) { ld ndist2 = cdist + ((ld)i.second / (ld)pow(2.0, (ld)k + 1)); if (ndist2 < dist[i.first][k+1]) { dist[i.first][k+1] = ndist2; pq.push(make_tuple(dist[i.first][k+1], k + 1, i.first)); } } } } return -1; }
#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...