Submission #1358614

#TimeUsernameProblemLanguageResultExecution timeMemory
1358614silence25Cyberland (APIO23_cyberland)C++20
15 / 100
621 ms33764 KiB
#include "cyberland.h"
#include "bits/stdc++.h"

#define ff first
#define ss second
#define pp pop_back
#define ll long long
#define pb push_back
#define ls(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define wr cout << "------------------------" << endl

using namespace std;

const int N = 1e5 + 5;
vector<pair<int, int>> g[N];

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    for(int i = 0;i<M;++i){
        g[x[i]].pb({c[i], y[i]});
        g[y[i]].pb({c[i], x[i]});
    }
    K = min(K, 70);
    priority_queue<array<double, 3>, vector<array<double, 3>>, greater<array<double, 3>>> pq;
    const double INF = 1e18;
    vector<vector<double>> dp(N, vector<double>(K + 1, INF));    
    pq.push({0, 0, 0});
    dp[0][0] = 0;
	for(int i = 0;i<N;++i){
		if(arr[i] == 0){
			pq.push({0, (double)i, 0});
			dp[i][0] = 0;
		}
	}
	while(!pq.empty()){
        auto [cost, xx, k] = pq.top(); pq.pop();
        int x = xx;
        if(dp[x][k] != cost or x == H) continue;
        for(auto [val, y]:g[x]){
            if(arr[y] == 2){
                double req1 = cost + val;
                double req2 = (cost + val) / 2;
                if(dp[y][k] > req1){
                    dp[y][k] = req1;
                    pq.push({req1, (double)y, k});
                }
                if(k + 1 <= K and dp[y][k + 1] > req2){
                    dp[y][k + 1] = req2;
                    pq.push({req2, (double)y, k + 1});
                }
            }
            // else if(!arr[y]){
            //     double req = 0;
            //     if(dp[y][k] > req){
            //         dp[y][k] = req;
            //         pq.push({req, (double)y, k});
            //     }
            // }
            else if(arr[y]){
                double req = cost + val;
                if(dp[y][k] > req){
                    dp[y][k] = req;
                    pq.push({req, (double)y, k});
                }
            }
        }
    }
    double ans = INF;
    for(int i = 0;i<=K;++i) ans = min(ans, dp[H][i]);
    for(int i = 0;i<N;++i){
        g[i].clear();
    }
    if(ans >= INF) ans = -1;
    return ans;
}

/*
1
3 2 30
2
1 2 1
1 2 12
2 0 4

1
4 4 30
3
1 0 2 1
0 1 5
0 2 4
1 3 2
2 3 4

*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...