답안 #985152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985152 2024-05-17T11:41:13 Z Kracken_180 사이버랜드 (APIO23_cyberland) C++17
20 / 100
2127 ms 2097152 KB
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <limits>
using namespace std;

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    const double INF = numeric_limits<double>::infinity();
    
    // Adjacency list representation of the graph
    vector<vector<pair<int, int>>> 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]);
    }
    
    // Priority queue to store the states as (current cost, current country, remaining K)
    priority_queue<tuple<double, int, int>, vector<tuple<double, int, int>>, greater<>> pq;
    pq.emplace(0.0, 0, K);
    
    // Distance table to store the minimum cost to reach each state
    vector<vector<double>> dist(N, vector<double>(K + 1, INF));
    dist[0][K] = 0.0;
    
    while (!pq.empty()) {
        auto [current_cost, u, remaining_k] = pq.top();
        pq.pop();
        
        if (u == H) {
            return current_cost;
        }
        
        // If we find a cheaper way to get here, continue
        if (current_cost > dist[u][remaining_k]) {
            continue;
        }
        
        for (auto &[v, travel_time] : graph[u]) {
            double new_cost = current_cost + travel_time;
            
            // Case 1: Normal travel without using special abilities
            if (new_cost < dist[v][remaining_k]) {
                dist[v][remaining_k] = new_cost;
                pq.emplace(new_cost, v, remaining_k);
            }
            
            // Case 2: Using zeroing ability
            if (arr[v] == 0 && current_cost < dist[v][remaining_k]) {
                dist[v][remaining_k] = current_cost;
                pq.emplace(current_cost, v, remaining_k);
            }
            
            // Case 3: Using halving ability
            if (arr[v] == 2 && remaining_k > 0) {
                double halved_cost = current_cost + travel_time / 2.0;
                if (halved_cost < dist[v][remaining_k - 1]) {
                    dist[v][remaining_k - 1] = halved_cost;
                    pq.emplace(halved_cost, v, remaining_k - 1);
                }
            }
        }
    }
    
    // If Cyberland is unreachable
    return -1.0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 576 KB Correct.
2 Correct 15 ms 604 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 812 KB Correct.
2 Correct 28 ms 848 KB Correct.
3 Correct 21 ms 860 KB Correct.
4 Correct 23 ms 828 KB Correct.
5 Correct 22 ms 824 KB Correct.
6 Correct 18 ms 3996 KB Correct.
7 Correct 27 ms 3968 KB Correct.
8 Correct 13 ms 7516 KB Correct.
9 Correct 22 ms 348 KB Correct.
10 Correct 22 ms 348 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 824 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 21404 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 820 KB Correct.
2 Correct 22 ms 600 KB Correct.
3 Correct 24 ms 1056 KB Correct.
4 Correct 27 ms 3732 KB Correct.
5 Correct 20 ms 348 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 860 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 133 ms 1136 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2127 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -