Submission #985348

#TimeUsernameProblemLanguageResultExecution timeMemory
985348CrazyBotBoyCyberland (APIO23_cyberland)C++17
15 / 100
1464 ms2097152 KiB
#include <iostream> #include <vector> #include <queue> #include <cmath> #include <limits> #include <tuple> #include <iomanip> const double INF = std::numeric_limits<double>::infinity(); struct State { double time; int country; int div2_used; bool operator>(const State& other) const { return time > other.time; } }; 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) { std::vector<std::vector<std::pair<int, double>>> graph(N); for (int i = 0; i < M; ++i) { graph[x[i]].emplace_back(y[i], c[i]); graph[y[i]].emplace_back(x[i], c[i]); } std::priority_queue<State, std::vector<State>, std::greater<State>> pq; pq.push({0, 0, 0}); std::vector<std::vector<double>> dist(N, std::vector<double>(K + 1, INF)); dist[0][0] = 0; while (!pq.empty()) { auto [current_time, current_country, div2_used] = pq.top(); pq.pop(); if (current_country == H) { return current_time; } if (current_time > dist[current_country][div2_used]) { continue; } for (const auto& [next_country, travel_time] : graph[current_country]) { double next_time = current_time + travel_time; if (next_time < dist[next_country][div2_used]) { dist[next_country][div2_used] = next_time; pq.push({next_time, next_country, div2_used}); } if (arr[next_country] == 0) { next_time = 0; if (next_time < dist[next_country][div2_used]) { dist[next_country][div2_used] = next_time; pq.push({next_time, next_country, div2_used}); } } else if (arr[next_country] == 2 && div2_used < K) { next_time = current_time / 2.0; if (next_time < dist[next_country][div2_used + 1]) { dist[next_country][div2_used + 1] = next_time; pq.push({next_time, next_country, div2_used + 1}); } } } } 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...