Submission #776243

# Submission time Handle Problem Language Result Execution time Memory
776243 2023-07-07T13:33:06 Z Alan Cyberland (APIO23_cyberland) C++17
68 / 100
2563 ms 98984 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;
}
# Verdict Execution time Memory Grader output
1 Correct 41 ms 528 KB Correct.
2 Correct 40 ms 724 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 151 ms 1096 KB Correct.
2 Correct 184 ms 1584 KB Correct.
3 Correct 172 ms 1548 KB Correct.
4 Correct 179 ms 1612 KB Correct.
5 Correct 178 ms 1596 KB Correct.
6 Correct 209 ms 5508 KB Correct.
7 Correct 258 ms 5336 KB Correct.
8 Correct 122 ms 9420 KB Correct.
9 Correct 118 ms 1068 KB Correct.
10 Correct 117 ms 1116 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 169 ms 1548 KB Correct.
2 Correct 174 ms 1504 KB Correct.
3 Correct 152 ms 1600 KB Correct.
4 Correct 119 ms 752 KB Correct.
5 Correct 118 ms 1224 KB Correct.
6 Correct 39 ms 3924 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 138 ms 23828 KB Correct.
2 Correct 111 ms 1504 KB Correct.
3 Correct 98 ms 1596 KB Correct.
4 Correct 109 ms 1564 KB Correct.
5 Correct 79 ms 1228 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 83 ms 1572 KB Correct.
2 Correct 86 ms 1548 KB Correct.
3 Correct 96 ms 1644 KB Correct.
4 Correct 112 ms 4944 KB Correct.
5 Correct 61 ms 1036 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 107 ms 1544 KB Correct.
2 Correct 79 ms 1452 KB Correct.
3 Correct 97 ms 30232 KB Correct.
4 Correct 64 ms 3500 KB Correct.
5 Correct 76 ms 1356 KB Correct.
6 Correct 83 ms 1308 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 108 ms 1496 KB Correct.
2 Correct 14 ms 980 KB Correct.
3 Incorrect 966 ms 33936 KB Wrong Answer.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 329 ms 2076 KB Correct.
2 Correct 42 ms 2132 KB Correct.
3 Correct 2563 ms 98984 KB Correct.
4 Incorrect 499 ms 6112 KB Wrong Answer.
5 Halted 0 ms 0 KB -