답안 #751867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751867 2023-06-01T17:10:59 Z aryan12 사이버랜드 (APIO23_cyberland) C++17
68 / 100
3000 ms 51896 KB
#include "cyberland.h"
#include <bits/stdc++.h>
#include <vector>
#define int long long
using namespace std;

const int N = 1e5 + 5, K = 71;
double dist[N][K];
vector<pair<int, double> > g[N];
bool vis[N], source[N];
int a[N], H;

void dfs(int node)
{
    vis[node] = true;
    if(a[node] == 0)
    {
        source[node] = true;
    }
    if(node == H)
    {
        return;
    }
    for(auto [to, wt]: g[node])
    {
        if(!vis[to])
        {
            dfs(to);
        }
    }
}

double solve(int32_t n, int32_t m, int32_t k, int32_t h, 
    vector<int32_t> x, vector<int32_t> y, vector<int32_t> c, 
    vector<int32_t> arr) 
{
    H = h;
    k = min(k, 70);
    for(int i = 0; i <= n; i++)
    {
        source[i] = false;
        vis[i] = false;
        if(i != n) a[i] = arr[i];
        g[i].clear();
        for(int j = 0; j <= k; j++)
        {
            dist[i][j] = 1e18;
        }
    }
    for(int i = 0; i < m; i++)
    {
        g[x[i]].push_back({y[i], c[i]});
        g[y[i]].push_back({x[i], c[i]});
    }
    dfs(0);
    source[0] = true;
    if(!vis[H])
    {
        return -1;
    }
    priority_queue<pair<double, pair<int, int> > > pq;
    for(int i = 0; i < n; i++)
    {
        // cout << "source[i] = " << source[i] << "\n";
        if(source[i])
        {
            pq.push({0, {i, 0}});
            dist[i][0] = 0;
        }
    }
    while(!pq.empty())
    {
        auto [dis, p] = pq.top();
        auto [node, cur_k] = p;
        pq.pop();
        if(dist[node][cur_k] < dis || node == h)
        {
            continue;
        }
        for(auto [to, wt]: g[node])
        {
            if(a[to] == 0) continue;
            if(dist[to][cur_k] > dist[node][cur_k] + wt)
            {
                dist[to][cur_k] = dist[node][cur_k] + wt;
                pq.push({dist[to][cur_k], {to, cur_k}});
            }
            if(a[to] == 1 || cur_k == k) continue;
            if(dist[to][cur_k + 1] > (dist[node][cur_k] + wt) / 2.0)
            {
                dist[to][cur_k + 1] = (dist[node][cur_k] + wt) / 2.0;
                pq.push({dist[to][cur_k + 1], {to, cur_k + 1}});
            }
        }
    }
    double ans = 1e18;
    // for(int i = 0; i < n; i++)
    // {
    //     for(int j = 0; j <= k; j++)
    //     {
    //         cout << "dist[" << i << "][" << j << "] = " << dist[i][j] << "\n";
    //     }
    // }
    for(int i = 0; i <= k; i++)
    {
        ans = min(ans, dist[h][i]);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2772 KB Correct.
2 Correct 21 ms 2772 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3324 KB Correct.
2 Correct 28 ms 3388 KB Correct.
3 Correct 24 ms 3412 KB Correct.
4 Correct 29 ms 3284 KB Correct.
5 Correct 29 ms 3488 KB Correct.
6 Correct 33 ms 9024 KB Correct.
7 Correct 29 ms 8996 KB Correct.
8 Correct 18 ms 15316 KB Correct.
9 Correct 24 ms 2816 KB Correct.
10 Correct 23 ms 2804 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3400 KB Correct.
2 Correct 30 ms 3412 KB Correct.
3 Correct 27 ms 3440 KB Correct.
4 Correct 28 ms 2796 KB Correct.
5 Correct 26 ms 2780 KB Correct.
6 Correct 9 ms 8020 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 40864 KB Correct.
2 Correct 512 ms 3440 KB Correct.
3 Correct 452 ms 3452 KB Correct.
4 Correct 463 ms 3428 KB Correct.
5 Correct 391 ms 2860 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 3404 KB Correct.
2 Correct 121 ms 3476 KB Correct.
3 Correct 128 ms 3436 KB Correct.
4 Correct 1216 ms 9520 KB Correct.
5 Correct 24 ms 2772 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3472 KB Correct.
2 Correct 28 ms 3532 KB Correct.
3 Correct 77 ms 51896 KB Correct.
4 Correct 63 ms 7728 KB Correct.
5 Correct 26 ms 2772 KB Correct.
6 Correct 34 ms 3552 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3090 ms 12644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 24068 KB Time limit exceeded
2 Halted 0 ms 0 KB -