Submission #968393

# Submission time Handle Problem Language Result Execution time Memory
968393 2024-04-23T11:26:34 Z akacool445k Cyberland (APIO23_cyberland) C++17
68 / 100
1414 ms 213356 KB
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
 
// #define int long long
#define ll long long
#define ff first
#define ss second
#define pint pair < double , int >
#define vint vector < int >
#define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL)

const double inf = 1e18 + 9;
const int mxn = 2e5 + 2;
const int mod = 1e9 + 7;
 
vector < vector < pint > > adj(mxn);
vint arr_;
double dis[77][mxn];
bool vis[mxn];

priority_queue < pint > q[77];

void dfs(int x , int par , int H) {
    if (vis[x]) return;
    vis[x] = 1;
    if (x == H) return;
    if (arr_[x] == 0) q[0].push({0 , x});
    for (pint i : adj[x]) {
        if (i.ss == par) continue;
        dfs(i.ss , x , H);
    }
}
 
double solve(int n , int m , int k , int H , vint x , vint y , vint c , vint arr) {

    for (int i = 0; i < n; i++) {
        adj[i].clear();
        vis[i] = 0;
    }

    k = min(k , 75);

    for (int i = 0; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            dis[i][j] = -1;
        }
    }

    arr_ = arr;
    for (int i = 0; i < m; i++) {
        adj[x[i]].push_back({c[i] , y[i]});
        adj[y[i]].push_back({c[i] , x[i]});
    }

    dfs(0 , 0 , H);
    q[0].push({0 , 0});

    for (int i = 0; i <= k; i++) {
        for(int u = 0; u < n; u++)
            vis[u] = 0;
        while (!q[i].empty()) {
            pint p = q[i].top();
            q[i].pop();
            
            if (vis[p.ss]) continue;
            vis[p.ss] = 1;
            dis[i][p.ss] = -p.ff;
            if (p.ss == H) continue;

            for (pint j : adj[p.ss]) {
                if (arr[j.ss] == 0) continue;
                q[i].push({p.ff - j.ff , j.ss});
                if (arr[j.ss] == 2) q[i+1].push({(p.ff - j.ff) / 2.0 , j.ss});
            }
        }
    }

    double ans = inf;
    for (int i = 0; i <= k; i++) {
        if (dis[i][H] != -1) ans = min(ans , dis[i][H]);
    }

    if (ans == inf) return -1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 52316 KB Correct.
2 Correct 23 ms 52312 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 28 ms 52572 KB Correct.
2 Correct 32 ms 52532 KB Correct.
3 Correct 31 ms 52312 KB Correct.
4 Correct 32 ms 52316 KB Correct.
5 Correct 31 ms 52492 KB Correct.
6 Correct 32 ms 53444 KB Correct.
7 Correct 36 ms 53356 KB Correct.
8 Correct 21 ms 54108 KB Correct.
9 Correct 29 ms 52416 KB Correct.
10 Correct 28 ms 52316 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 31 ms 52312 KB Correct.
2 Correct 31 ms 52312 KB Correct.
3 Correct 32 ms 52828 KB Correct.
4 Correct 29 ms 52312 KB Correct.
5 Correct 29 ms 52312 KB Correct.
6 Correct 12 ms 53084 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 104 ms 63696 KB Correct.
2 Correct 98 ms 53056 KB Correct.
3 Correct 88 ms 53104 KB Correct.
4 Correct 89 ms 52924 KB Correct.
5 Correct 57 ms 52744 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 27 ms 52548 KB Correct.
2 Correct 31 ms 52572 KB Correct.
3 Correct 30 ms 52688 KB Correct.
4 Correct 33 ms 53972 KB Correct.
5 Correct 26 ms 52316 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 28 ms 52572 KB Correct.
2 Correct 25 ms 52568 KB Correct.
3 Correct 42 ms 61268 KB Correct.
4 Correct 21 ms 53592 KB Correct.
5 Correct 27 ms 52316 KB Correct.
6 Correct 29 ms 52544 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 184 ms 53964 KB Correct.
2 Correct 37 ms 53340 KB Correct.
3 Correct 573 ms 46096 KB Correct.
4 Correct 378 ms 47148 KB Correct.
5 Correct 606 ms 89124 KB Correct.
6 Correct 534 ms 94036 KB Correct.
7 Correct 388 ms 53684 KB Correct.
8 Incorrect 299 ms 53104 KB Wrong Answer.
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 363 ms 127060 KB Correct.
2 Correct 81 ms 126336 KB Correct.
3 Correct 264 ms 140084 KB Correct.
4 Correct 449 ms 126288 KB Correct.
5 Correct 1414 ms 194984 KB Correct.
6 Correct 1237 ms 213356 KB Correct.
7 Correct 850 ms 138064 KB Correct.
8 Incorrect 351 ms 125012 KB Wrong Answer.
9 Halted 0 ms 0 KB -