제출 #896767

#제출 시각아이디문제언어결과실행 시간메모리
896767NotLinux사이버랜드 (APIO23_cyberland)C++17
49 / 100
1813 ms15180 KiB
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < pair < ll , ll > , pair < int , int > > VAR;
const int MAXK = 31;

inline pair < ll , ll > subt(pair < ll , ll > a , pair < ll , ll > b){
    ll pay = a.first * b.second - a.second * b.first;
    ll payda = a.second * b.second;
    ll gc = gcd(pay , payda);
    return {pay/gc , payda/gc};
}
struct cmp{
    bool operator()(VAR a , VAR b){
        return a.first.first * b.first.second < a.first.second * b.first.first;
    }
};
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) {
    bitset < 31 > vis[n];
    fill(vis , vis + n , 0);
 
    vector < pair < int , int > > graph[n];
    for(int i = 0;i<m;i++){
        graph[x[i]].push_back({y[i] , c[i]});
        graph[y[i]].push_back({x[i] , c[i]});
    }
 
    priority_queue < VAR , vector < VAR > , cmp > pq;//dist , node , how much k used
    pq.push({{0,1},{0,0}});
 
    function < void (int) > dfs = [&](int cur){
        if(vis[cur] == 1 or cur == h)return;
        vis[cur] = 1;
        if(arr[cur] == 0){
            pq.push({{0,1},{cur,0}});
            // cout << "pushed : " << cur << endl;
        }
        for(auto itr : graph[cur]){
            dfs(itr.first);
        }
    };
 
    dfs(0);
    fill(vis , vis + n , 0);
 
    double ans = 1;
    while(pq.size()){
        VAR tmp = pq.top();
        pq.pop();
        if(vis[tmp.second.first][tmp.second.second])continue;
        vis[tmp.second.first][tmp.second.second] = 1;
        // cout << "pq : " << tmp.first.first << " / " << tmp.first.second << " , " << tmp.second.first << " " << tmp.second.second << endl;
        double reelval = (double)tmp.first.first / (double)tmp.first.second;
        if(tmp.second.first == h){
            if(ans == 1 or ans < reelval){
                ans = reelval;
            }
        }
        else{
            for(auto itr : graph[tmp.second.first]){
                if(arr[tmp.second.first] == 2 and tmp.second.second < k){
                    pq.push({subt({tmp.first.first , tmp.first.second * 2ll},{itr.second , 1ll}) , {itr.first , tmp.second.second+1}});
                }
                pq.push({subt(tmp.first , {itr.second , 1ll}) , {itr.first , tmp.second.second}});
            }
        }
    }
    return -ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...