제출 #1171869

#제출 시각아이디문제언어결과실행 시간메모리
1171869rayan_bd사이버랜드 (APIO23_cyberland)C++20
15 / 100
3095 ms29584 KiB
// not my code, code by ai

#include <bits/stdc++.h>
using namespace std;

const double INF = 1e18;
const int mxN = 2e5+100;
const int mxK = 32;

double dp[mxN][mxK];
vector<pair<int, double>> adj[mxN];

struct State {
    int node, usedK;
    double cost;
    bool operator>(const State &other) const { return cost > other.cost; }
};

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    // Reset adjacency list and dp array
    for (int i = 0; i < N; ++i) {
        adj[i].clear();
        for (int j = 0; j <= K; ++j) dp[i][j] = INF;
    }

    // Build adjacency list
    for (int i = 0; i < M; ++i) {
        adj[x[i]].emplace_back(y[i], c[i]);
        adj[y[i]].emplace_back(x[i], c[i]);
    }

    priority_queue<State, vector<State>, greater<State>> pq;
    dp[0][0] = 0.0;
    pq.push({0, 0, 0.0});

    while (!pq.empty()) {
        auto [u, usedK, cost] = pq.top();
        pq.pop();
        
        if (cost > dp[u][usedK]) continue;

        for (auto [v, w] : adj[u]) {
            double new_cost = cost + w;
            if (arr[v] == 0) new_cost = 0; // Reset time if special ability 0
            
            if (dp[v][usedK] > new_cost) {
                dp[v][usedK] = new_cost;
                pq.push({v, usedK, new_cost});
            }

            if (arr[v] == 2 && usedK < K) {
                double reduced_cost = new_cost / 2.0;
                if (dp[v][usedK + 1] > reduced_cost) {
                    dp[v][usedK + 1] = reduced_cost;
                    pq.push({v, usedK + 1, reduced_cost});
                }
            }
        }
    }

    double result = INF;
    for (int i = 0; i <= K; ++i) result = min(result, dp[H][i]);
    return (result == INF) ? -1 : result;
}
#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...