Submission #749992

# Submission time Handle Problem Language Result Execution time Memory
749992 2023-05-29T03:16:52 Z I_love_Hoang_Yen Cyberland (APIO23_cyberland) C++17
20 / 100
38 ms 3540 KB
#include "cyberland.h"
#include <bits/stdc++.h>
#define SZ(s) ((int) ((s).size()))
using namespace std;

const int ZERO = 0;
const int NORMAL = 1;
const int DIV2 = 2;

void upMin(double& res, double val) {
    if (res < -0.5) res = val;
    else res = min(res, val);
}

// N <= 3
double sub1(
        int n, int maxDiv2, int target,
        const vector<tuple<int,int,int>>& edges,
        const vector<int>& node_types) {
    if (target == 0) {
        return 0.0;
    }

    double res = -1;
    vector<vector<double>> costs(n, vector<double> (n, -1));
    for (auto [u, v, cost] : edges) {
        costs[u][v] = costs[v][u] = cost;
    }

    // go directly from 0 -> target
    if (costs[0][target] >= 0)
        upMin(res, costs[0][target]);
    if (n <= 2) return res;

    // go 0 -> other vertex -> target
    int other = 3 - target;
    if (costs[0][other] >= 0 && costs[other][target] >= 0) {
        switch (node_types[other]) {
            case NORMAL:
                upMin(res, costs[0][other] + costs[other][target]);
                break;
            case ZERO:
                upMin(res, costs[other][target]);
                break;
            case DIV2:
                if (maxDiv2 >= 1) {
                    upMin(res, costs[0][other] / 2.0 + costs[other][target]);
                } else {
                    upMin(res, costs[0][other] + costs[other][target]);
                }
                break;
        }
    }
    return res;
}

// All nodes are NORMAL
double sub25(
        int n, int target,
        const vector<vector<pair<int,int>>> g) {
    const int64_t INF = 1e18;
    vector<int64_t> dists(n, INF);
    set<pair<int64_t, int>> all;
    dists[0] = 0;
    all.insert({0LL, 0});
    while (!all.empty()) {
        auto [dist, u] = *all.begin();
        all.erase(all.begin());
        if (dist != dists[u]) continue;

        for (auto [v, cost] : g[u]) {
            int64_t cur = dist + cost;
            if (cur < dists[v]) {
                dists[v] = cur;
                all.insert({cur, v});
            }
        }
    }
    if (dists[target] == INF) dists[target] = -1;
    return dists[target];
}

double solve(
        int n, int m, int maxDiv2, int target,
        vector<int> edge_froms,
        vector<int> edge_tos,
        vector<int> edge_costs,
        vector<int> node_types) {

    assert(m == SZ(edge_froms));
    assert(m == SZ(edge_tos));
    assert(m == SZ(edge_costs));
    assert(n == SZ(node_types));

    if (n <= 3) {
        vector<tuple<int,int,int>> edges(m);
        for (int i = 0; i < m; ++i) {
            assert(0 <= edge_froms[i] && edge_froms[i] < n);
            assert(0 <= edge_tos[i] && edge_tos[i] < n);
            assert(1 <= edge_costs[i] && edge_costs[i] < 1000111000);
            edges[i] = {
                edge_froms[i],
                edge_tos[i],
                edge_costs[i]
            };
        }

        return sub1(
                n, maxDiv2, target,
                edges, node_types);
    }

    int minType = *min_element(node_types.begin(), node_types.end());
    int maxType = *max_element(node_types.begin(), node_types.end());
    if (minType == 1 && maxType == 1) {
        vector<vector<pair<int,int>>> g(n);
        for (int i = 0; i < m; ++i) {
            int u = edge_froms[i];
            int v = edge_tos[i];
            int cost = edge_costs[i];

            g[u].emplace_back(v, cost);
            g[v].emplace_back(u, cost);
        }
        return sub25(n, target, g);
    }
    return 0.0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 468 KB Correct.
2 Correct 21 ms 444 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 27 ms 468 KB Correct.
2 Correct 31 ms 492 KB Correct.
3 Correct 30 ms 472 KB Correct.
4 Correct 31 ms 492 KB Correct.
5 Correct 33 ms 496 KB Correct.
6 Correct 26 ms 1900 KB Correct.
7 Correct 37 ms 1824 KB Correct.
8 Correct 15 ms 3540 KB Correct.
9 Correct 32 ms 400 KB Correct.
10 Correct 31 ms 340 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 340 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2124 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 532 KB Correct.
2 Correct 33 ms 592 KB Correct.
3 Correct 38 ms 612 KB Correct.
4 Correct 26 ms 1876 KB Correct.
5 Correct 32 ms 340 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 384 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 364 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 340 KB Wrong Answer.
2 Halted 0 ms 0 KB -