답안 #986649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986649 2024-05-21T01:45:55 Z CSQ31 사이버랜드 (APIO23_cyberland) C++17
0 / 100
51 ms 37408 KB
#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
//typedef long long int ll;
typedef __int128 ll;
#define fi first
#define se second
ll dist[31][111111];
ll pw[31];
vector<pair<int,int>>adj[111111];
struct node{
    int v;
    int k;
    ll d = 0;
    node(){}
    node(int _k,int _v,ll _d = 0){
        v = _v;
        k = _k;
        d = _d;
    }
};
struct comp{
    bool operator() (node a, node b) {return a.d > b.d;}
};
std::ostream& operator<<(std::ostream& o, const __int128& x) {
    if (x == std::numeric_limits<__int128>::min()) return o << "-170141183460469231731687303715884105728";
    if (x < 0) return o << "-" << -x;
    if (x < 10) return o << (char)(x + '0');
    return o << x / 10 << (char)(x % 10 + '0');
}
double solve(int n, int m,int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
    for(int j=0;j<n;j++){
        adj[j].clear();
        for(int i=0;i<=30;i++){
            dist[i][j] = numeric_limits<__int128>::max();
        }
    }
    pw[0] = 1;
    for(int i=1;i<=30;i++)pw[i] = pw[i-1]*2;
    for(int i=0;i<m;i++){
        adj[x[i]].push_back({y[i],c[i]});
        adj[y[i]].push_back({x[i],c[i]});
    }
    
    priority_queue<node,vector<node>,comp>pq;
    dist[0][H] = 0;
    pq.push(node(0,H));
    while(!pq.empty()){
        int v = pq.top().v;
        int k = pq.top().k;
        ll d = pq.top().d;
        pq.pop();
        if(arr[v] == 0)continue;
        if(d != dist[k][v])continue;
       // cout<<k<<" "<<v<<" "<<d/pw[30]<<'\n';
        for(auto x:adj[v]){
            int u = x.fi;
            ll w = x.se;
            w *= pw[30-k];
            if(u == H)continue;
            if(dist[k][u] > d + w){
                dist[k][u] = d + w;
                pq.push(node(k,u,d+w));
            }
            if(arr[u] == 2 && k+1 <= K && dist[k+1][u] > d + w){
                dist[k+1][u] = d + w;
                pq.push(node(k+1,u,d + w));
            }
        }
    }



    ll ans = dist[0][0];
    for(int i=0;i<=K;i++)ans = min(ans,dist[i][0]);
    queue<int>q;
    vector<int>vis(n,0);
    q.push(0);
    vis[0] = 1;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if(arr[v] == 0)for(int i=0;i<=K;i++)ans = min(ans,dist[i][v]);
        for(auto x:adj[v]){
            int u = x.first;
            if(!vis[u]){
                q.push(u);
                vis[u] = 1;
            }
        }
    }
    if(!vis[H])return -1;
    long double fin = 0;
    for(int i=0;i<30;i++){
        if(ans&1){
            long double kekw = 1;
            kekw /= (1LL<<(30-i));
            fin += kekw;
        }
        ans/=2;
    }
    fin += ans;
    return fin;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 3672 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 4696 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 4700 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 37408 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 4700 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 4556 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 4696 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 6748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -