답안 #969006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969006 2024-04-24T11:18:50 Z sleepntsheep 사이버랜드 (APIO23_cyberland) C++17
100 / 100
173 ms 67924 KB
#include "cyberland.h"

#include <tuple>
#include <vector>
#include <queue>
#include <utility>


#define MAX_N 100001
#define MAX_M 200001
#define MAX_K 74

int head[MAX_N], nxt[MAX_M], vv[MAX_M];

int ds[MAX_N];
int ds_find(int i){return ds[i]==i?i:(ds[i]=ds_find(ds[i]));}

double ww[MAX_M],d[MAX_N][MAX_K],p2[MAX_K];

int i = 1;
void link(int u, int v, int w)
{
    nxt[i] = head[u];
    vv[i] = v;
    ww[i] = w;
    head[u] = i++;
}

double solve(int n, int m, int kk, int h, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
    for(int i=0;i<n;++i)head[i]=0,ds[i]=i;
    i=1;
    p2[0]=1;for(int j=1;j<MAX_K;++j)p2[j]=p2[j-1]/2;

    if (kk >= MAX_K) kk = MAX_K - 1;

    for (int i = 0; i < m; ++i)
    {
        if(x[i]!=h&&y[i]!=h)
        ds[ds_find(y[i])]=ds_find(x[i]); link(x[i], y[i], c[i]), link(y[i], x[i], c[i]);
    }

    for (int i = 0; i < n; ++i) for (int j = 0; j <= kk; ++j) d[i][j] = 1e18;

    arr[0]=0;
    using T = std::tuple<double, int, int>;
    std::priority_queue<T, std::vector<T>, std::greater<T> >pq;

    auto nq = [&](double cost, int u, int k) { if (cost<d[u][k])d[u][k]=cost,pq.emplace(cost,u,k); };
    nq(0,h,0);

    while (pq.size())
    {
        auto[c,u,k]=pq.top();pq.pop();
        if (d[u][k]!=c)continue;
        if(ds_find(u)==ds_find(0)&&arr[u]==0)return c;

        for(int j=head[u];j;j=nxt[j])
        {
            int v=vv[j];
            if(ds_find(v)!=ds_find(0))continue;
            double w=ww[j];

            nq(c+w*p2[k], v, k);
            if(arr[v]==2&&k<kk)
                nq(c+w*p2[k],v,k+1);
        }
    }

    return -1;
}

Compilation message

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:38:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   38 |         if(x[i]!=h&&y[i]!=h)
      |         ^~
cyberland.cpp:39:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   39 |         ds[ds_find(y[i])]=ds_find(x[i]); link(x[i], y[i], c[i]), link(y[i], x[i], c[i]);
      |                                          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4952 KB Correct.
2 Correct 15 ms 4956 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 7456 KB Correct.
2 Correct 21 ms 7516 KB Correct.
3 Correct 21 ms 7524 KB Correct.
4 Correct 20 ms 7524 KB Correct.
5 Correct 21 ms 7524 KB Correct.
6 Correct 18 ms 11876 KB Correct.
7 Correct 22 ms 11852 KB Correct.
8 Correct 10 ms 18264 KB Correct.
9 Correct 20 ms 5212 KB Correct.
10 Correct 19 ms 5212 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7624 KB Correct.
2 Correct 19 ms 7604 KB Correct.
3 Correct 18 ms 7784 KB Correct.
4 Correct 19 ms 5428 KB Correct.
5 Correct 21 ms 5472 KB Correct.
6 Correct 5 ms 11104 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 42332 KB Correct.
2 Correct 18 ms 7772 KB Correct.
3 Correct 17 ms 7772 KB Correct.
4 Correct 17 ms 7772 KB Correct.
5 Correct 20 ms 5464 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7488 KB Correct.
2 Correct 22 ms 7512 KB Correct.
3 Correct 20 ms 7520 KB Correct.
4 Correct 20 ms 11792 KB Correct.
5 Correct 18 ms 5212 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7508 KB Correct.
2 Correct 17 ms 7512 KB Correct.
3 Correct 36 ms 53992 KB Correct.
4 Correct 17 ms 9600 KB Correct.
5 Correct 20 ms 5724 KB Correct.
6 Correct 18 ms 7768 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7512 KB Correct.
2 Correct 4 ms 7004 KB Correct.
3 Correct 47 ms 65056 KB Correct.
4 Correct 38 ms 19796 KB Correct.
5 Correct 28 ms 29016 KB Correct.
6 Correct 22 ms 14152 KB Correct.
7 Correct 37 ms 21408 KB Correct.
8 Correct 37 ms 8796 KB Correct.
9 Correct 18 ms 7712 KB Correct.
10 Correct 18 ms 7768 KB Correct.
11 Correct 39 ms 8840 KB Correct.
12 Correct 19 ms 7880 KB Correct.
13 Correct 19 ms 7772 KB Correct.
14 Correct 39 ms 34308 KB Correct.
15 Correct 36 ms 15192 KB Correct.
16 Correct 22 ms 7896 KB Correct.
17 Correct 21 ms 7772 KB Correct.
18 Correct 19 ms 7884 KB Correct.
19 Correct 36 ms 8796 KB Correct.
20 Correct 3 ms 4696 KB Correct.
21 Correct 3 ms 6752 KB Correct.
22 Correct 3 ms 7008 KB Correct.
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7484 KB Correct.
2 Correct 4 ms 7008 KB Correct.
3 Correct 70 ms 67924 KB Correct.
4 Correct 38 ms 11136 KB Correct.
5 Correct 31 ms 28504 KB Correct.
6 Correct 29 ms 14168 KB Correct.
7 Correct 40 ms 28648 KB Correct.
8 Correct 40 ms 8784 KB Correct.
9 Correct 19 ms 7760 KB Correct.
10 Correct 19 ms 7772 KB Correct.
11 Correct 173 ms 5716 KB Correct.
12 Correct 20 ms 7772 KB Correct.
13 Correct 19 ms 7768 KB Correct.
14 Correct 37 ms 30552 KB Correct.
15 Correct 42 ms 37148 KB Correct.
16 Correct 38 ms 17572 KB Correct.
17 Correct 37 ms 8700 KB Correct.
18 Correct 20 ms 8020 KB Correct.
19 Correct 21 ms 7768 KB Correct.
20 Correct 21 ms 7768 KB Correct.
21 Correct 40 ms 8784 KB Correct.
22 Correct 3 ms 4696 KB Correct.
23 Correct 3 ms 6836 KB Correct.
24 Correct 3 ms 7000 KB Correct.