답안 #772716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772716 2023-07-04T10:42:35 Z boris_mihov 사이버랜드 (APIO23_cyberland) C++17
15 / 100
32 ms 9268 KB
#include "cyberland.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>

typedef long long llong;
const int MAXN = 100000 + 10;
const llong INF = 1e18;
const int INTINF = 1e9;

int n, m, k, h;
bool vis[MAXN];
llong dist[MAXN];
int ability[MAXN];
std::vector <std::pair <int,int>> g[MAXN];
std::priority_queue <std::pair <llong,int>> pq;
double toReach[MAXN];

void reset()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        g[i].clear();
        dist[i] = ability[i] = 0;
        toReach[i] = 0.0;
        vis[i] = false;
    }

    while (!pq.empty())
    {
        pq.pop();
    }
}

void dfs(int node)
{
    vis[node] = true;
    for (const auto &[u, e] : g[node])
    {
        if (vis[u])
        {
            continue;
        }

        dfs(u);
    }
}

double solve(int N, int M, int K, int H, std::vector <int> x, std::vector <int> y, std::vector <int> c, std::vector <int> arr) 
{
    n = N;
    m = M;
    k = K;
    h = H + 1;
    reset();

    for (int i = 0 ; i < m ; ++i)
    {
        g[x[i] + 1].emplace_back(y[i] + 1, c[i]);
        g[y[i] + 1].emplace_back(x[i] + 1, c[i]);
    }

    dfs(1);
    if (!vis[h])
    {
        return -1;
    }

    for (int i = 2 ; i <= n ; ++i)
    {
        ability[i] = arr[i - 1];
    }

    std::fill(dist + 1, dist + 1 + n, INF);
    for (int i = 1 ; i <= n ; ++i)
    {
        if (!vis[i]) continue;
        if (ability[i] == 0)
        {
            dist[i] = 0;
            pq.push({0, i});
        }
    }

    std::fill(vis + 1, vis + 1 + n, false);
    while (!pq.empty())
    {
        auto [currDist, node] = pq.top();
        pq.pop();

        if (vis[node])
        {
            continue;
        }
        
        vis[node] = true;
        for (const auto &[u, e] : g[node])
        {
            if (dist[u] > dist[node] + e)
            {
                dist[u] = dist[node] + e;
                pq.push({-dist[u], u});
            }
        }
    }

    return dist[h];
    for (int i = 1 ; i <= n ; ++i)
    {
        toReach[i] = dist[i];
        if (ability[i] == 2)
        {
            int minEdge = INTINF;
            for (const auto &[u, e] : g[i])
            {
                minEdge = std::min(minEdge, u);
            }

            toReach[i] /= 2.0;
            if (k > 60)
            {
                toReach[i] = std::min(toReach[i], (double)minEdge);
                break;
            }

            for (int j = 0 ; j < k && toReach[i] >= minEdge ; ++j)
            {
                toReach[i] += minEdge;
                toReach[i] /= 2.0;
            }
        }
    }

    std::fill(vis + 1, vis + 1 + n, false);
    std::fill(dist + 1, dist + 1 + n, INF);
    pq.push({0, h});
    dist[h] = 0;

    while (!pq.empty())
    {
        auto [currDist, node] = pq.top();
        pq.pop();

        if (vis[node])
        {
            continue;
        }
        
        vis[node] = true;
        for (const auto &[u, e] : g[node])
        {
            if (dist[u] > dist[node] + e)
            {
                dist[u] = dist[node] + e;
                pq.push({-dist[u], u});
            }
        }
    }

    double ans = INF;
    for (int i = 1 ; i <= n ; ++i)
    {
        ans = std::min(ans, (double)dist[i] + toReach[i]);
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 2780 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2772 KB Correct.
2 Correct 25 ms 2820 KB Correct.
3 Correct 24 ms 2772 KB Correct.
4 Correct 20 ms 2796 KB Correct.
5 Correct 19 ms 2804 KB Correct.
6 Correct 17 ms 3540 KB Correct.
7 Correct 23 ms 3596 KB Correct.
8 Correct 11 ms 4512 KB Correct.
9 Correct 19 ms 2740 KB Correct.
10 Correct 18 ms 2740 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 2784 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 9268 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2900 KB Correct.
2 Correct 20 ms 2884 KB Correct.
3 Correct 19 ms 2900 KB Correct.
4 Correct 19 ms 3720 KB Correct.
5 Correct 16 ms 2644 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 2900 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 2828 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 2888 KB Wrong Answer.
2 Halted 0 ms 0 KB -