Submission #1030856

# Submission time Handle Problem Language Result Execution time Memory
1030856 2024-07-22T10:50:35 Z amine_aroua Cyberland (APIO23_cyberland) C++17
44 / 100
39 ms 28032 KB
#include "cyberland.h"

#include <bits/stdc++.h>
using namespace std;
void dfs(int x , vector<bool>&reach , vector<vector<pair<int ,int>>> &adj , int H)
{
    if(reach[x])
        return ;
    reach[x] = 1;
    for(auto [u , cost] : adj[x])
    {
        if(u != H)
            dfs(u , reach , adj , H);
    }    
}
using Node = tuple<double , int , int>;
priority_queue<Node , vector<Node> , greater<Node>> pq;
void upd(int x , int k , double d , vector<vector<double>> &dist)
{
    if(dist[x][k] > d)
    {
        dist[x][k] = d;
        pq.push({d , x , k});
    }
}
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) 
{
    pq = priority_queue<Node , vector<Node> , greater<Node>> ();
    K = min(K , 70);
    vector<vector<pair<int , int>>> adj(N);
    vector<bool> reach(N);
    vector<double> pwr(K + 1);
    pwr[0] = 1;
    for(int i = 1 ; i <= K ; i++)
    {
        pwr[i] = pwr[i - 1]/2.0;
    } 
    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]});
    }
    vector<vector<double>> dist(N , vector<double>(K + 1 , 1e16));
    arr[0] = 0;
    pq.push({0 , H , 0});
    dist[H][0] = 0;
    dfs(0 , reach ,adj ,H);
    
    while(!pq.empty())
    {
        auto [d , x , k] = pq.top();
        pq.pop();
        if(arr[x] == 0)
        {
            return d;
        }
        for(auto [u , cost] : adj[x])
        {
            if(!reach[u])
                continue;
            upd(u , k , cost*pwr[k] + d , dist);
            if(arr[u] == 2 && k < K)
            {
                int p = k + 1;
                upd(u , p , cost*pwr[p] + d , dist);
            }
        }
    }
    return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 604 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 604 KB Correct.
2 Correct 22 ms 840 KB Correct.
3 Correct 21 ms 828 KB Correct.
4 Correct 21 ms 836 KB Correct.
5 Correct 22 ms 828 KB Correct.
6 Correct 27 ms 3992 KB Correct.
7 Correct 35 ms 3932 KB Correct.
8 Correct 9 ms 7516 KB Correct.
9 Correct 18 ms 488 KB Correct.
10 Correct 18 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 17 ms 812 KB Correct.
2 Correct 17 ms 840 KB Correct.
3 Correct 16 ms 860 KB Correct.
4 Correct 18 ms 348 KB Correct.
5 Correct 18 ms 348 KB Correct.
6 Correct 4 ms 3152 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 21848 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 824 KB Correct.
2 Correct 20 ms 604 KB Correct.
3 Correct 19 ms 804 KB Correct.
4 Correct 19 ms 3928 KB Correct.
5 Correct 23 ms 556 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 18 ms 888 KB Correct.
2 Correct 16 ms 852 KB Correct.
3 Correct 39 ms 28032 KB Correct.
4 Correct 13 ms 2584 KB Correct.
5 Correct 18 ms 544 KB Correct.
6 Correct 19 ms 824 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 832 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1080 KB Wrong Answer.
2 Halted 0 ms 0 KB -