답안 #775978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775978 2023-07-07T08:01:04 Z Sharky 사이버랜드 (APIO23_cyberland) C++17
68 / 100
3000 ms 98124 KB
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
const double INF = 1E18;
 
struct node {
    double di;
    int u, k;
    bool operator > (const node& o) const {
        return di < o.di;
    }
};
 
double solve(int32_t N, int32_t M, int32_t K, int32_t H, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> arr) {
    K = min(K, 120);
    vector<pair<int, int>> adj[N];
    vector<vector<double>> d(N, vector<double> (K + 1, INF));
    for (int i = 0; i < M; i++) {
        if (x[i] != H) adj[x[i]].push_back({y[i], c[i]});
        if (y[i] != H) adj[y[i]].push_back({x[i], c[i]});
    }
    queue<int> q;
    vector<bool> vis(N, 0);
    vis[0] = 1;
    q.push(0);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto& [v, w] : adj[u]) {
            if (!vis[v]) {
                vis[v] = true;
                q.push(v);
            }
        }
    }
    using T = node;
    priority_queue<T, vector<T>, greater<T>> pq;
    pq.push({0.0, 0, 0});
    d[0][0] = 0.0;
    for (int i = 0; i < N; i++) if (arr[i] == 0 && vis[i]) {
        pq.push({0.0, i, 0});
        d[i][0] = 0.0;
    }
    queue<node> Q;
    for (int i = 1; i <= K; i++) {
        while (!pq.empty()) {
            auto [di, u, k] = pq.top();
            pq.pop();
            if (di != d[u][k]) continue;
            for (auto& [v, w] : adj[u]) {
                double new_weight = d[u][k] + w;
                if (d[v][k] > new_weight) {
                    d[v][k] = new_weight;
                    pq.push((node) {d[v][k], v, k});
                }
            }
        }
        for (int j = 0; j < N; j++) if (d[j][i-1] < 1e17) Q.push({d[j][i - 1], j, i - 1});
        while (!Q.empty()) {
            auto [di, u, k] = Q.front();
            Q.pop();
            if (k >= i) continue;
            for (auto& [v, w] : adj[u]) {
                if (arr[v] == 0 || arr[v] == 1) continue;
                if (arr[v] == 2 && k != K) {
                    double new_weight = d[u][k] + w;
                    new_weight /= 2.0;
                    if (d[v][k + 1] > new_weight) {
                        d[v][k + 1] = new_weight;
                        Q.push((node) {d[v][k + 1], v, k + 1});
                    }
                }
            }
        }
        for (int j = 0; j < N; j++) {
            d[j][i] = min(d[j][i], d[j][i - 1]);
        }
        for (int j = 0; j < N; j++) if (d[j][i] < 1e17) pq.push({d[j][i], j, i});
    }
    // for (int i = 0; i <= H; i++) {
    //     for (int j = 0; j <= K; j++) {
    //         cout << i << " " << j << " ";
    //         cout << fixed << setprecision(6) << d[i][j] << "\n";
    //     }
    // }
    double res = *min_element(d[H].begin(), d[H].end());
    if (res >= INF) return -1;
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 392 KB Correct.
2 Correct 48 ms 388 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 752 KB Correct.
2 Correct 197 ms 748 KB Correct.
3 Correct 190 ms 744 KB Correct.
4 Correct 191 ms 764 KB Correct.
5 Correct 183 ms 752 KB Correct.
6 Correct 223 ms 4616 KB Correct.
7 Correct 304 ms 4604 KB Correct.
8 Correct 124 ms 8916 KB Correct.
9 Correct 104 ms 384 KB Correct.
10 Correct 101 ms 388 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 844 KB Correct.
2 Correct 143 ms 736 KB Correct.
3 Correct 129 ms 760 KB Correct.
4 Correct 100 ms 400 KB Correct.
5 Correct 106 ms 644 KB Correct.
6 Correct 40 ms 3796 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 22856 KB Correct.
2 Correct 99 ms 756 KB Correct.
3 Correct 90 ms 768 KB Correct.
4 Correct 110 ms 716 KB Correct.
5 Correct 73 ms 404 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 676 KB Correct.
2 Correct 180 ms 728 KB Correct.
3 Correct 194 ms 652 KB Correct.
4 Correct 1222 ms 4200 KB Correct.
5 Correct 61 ms 340 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 804 KB Correct.
2 Correct 67 ms 708 KB Correct.
3 Correct 96 ms 29328 KB Correct.
4 Correct 84 ms 2968 KB Correct.
5 Correct 64 ms 340 KB Correct.
6 Correct 76 ms 744 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 716 KB Correct.
2 Correct 24 ms 852 KB Correct.
3 Execution timed out 3078 ms 27596 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 1436 KB Correct.
2 Correct 51 ms 2004 KB Correct.
3 Correct 2162 ms 98124 KB Correct.
4 Incorrect 737 ms 4784 KB Wrong Answer.
5 Halted 0 ms 0 KB -