제출 #990693

#제출 시각아이디문제언어결과실행 시간메모리
990693Ibrohim0704사이버랜드 (APIO23_cyberland)C++17
0 / 100
834 ms2097152 KiB
#include <iostream> #include <vector> #include <queue> #include <climits> using namespace std; struct Node { int country; int passing_time; int divide_count; Node(int c, int t, int d) : country(c), passing_time(t), divide_count(d) {} bool operator<(const Node& other) const { return passing_time > other.passing_time; } }; double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { vector<vector<pair<int, int>>> graph(N); for (int i = 0; i < M; ++i) { graph[x[i]].push_back({y[i], c[i]}); graph[y[i]].push_back({x[i], c[i]}); } priority_queue<Node> pq; pq.push(Node(0, 0, 0)); vector<vector<vector<int>>> dp(N, vector<vector<int>>(K + 1, vector<int>(N, INT_MAX))); while (!pq.empty()) { Node curr = pq.top(); pq.pop(); if (curr.country == H) { return curr.passing_time; } if (dp[curr.country][curr.divide_count][curr.passing_time] != INT_MAX) { continue; // Already visited this state with a better passing time } dp[curr.country][curr.divide_count][curr.passing_time] = curr.passing_time; for (auto& neighbor : graph[curr.country]) { int next_country = neighbor.first; int next_time = curr.passing_time + neighbor.second; int next_divide_count = curr.divide_count; if (arr[next_country] == 2 && next_divide_count < K) { next_time /= 2; next_divide_count++; } pq.push(Node(next_country, next_time, next_divide_count)); } } return -1; // Cannot reach Cyberland }
#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...