답안 #975245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975245 2024-05-04T15:33:41 Z ShaShi 사이버랜드 (APIO23_cyberland) C++17
0 / 100
62 ms 91560 KB
#include <bits/stdc++.h>
#include "cyberland.h"
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define F first
#define S second


using namespace std;

typedef long long ll;


const int MAXN = (int)1e6 + 7;
const int K = 70;
const int MOD = 998244353;
const double INF = (double)1e18 + 7;


int n, m, k, h, tmp, tmp2, tmp3, tmp4, ans, u, v, w;
int arr[MAXN];
double dp[MAXN][K], p2[K];
bool seen[MAXN], sn[MAXN][K];
vector<pii> adj[MAXN];
priority_queue<pair<double, pii>, vector<pair<double, pii> >, greater<pair<double, pii> > > pq;



void DFS(int v) {
    seen[v] = 1;
    
    for (auto cur:adj[v]) {
        int u = cur.F, w = cur.S;

        if (!seen[u] && u != h) DFS(u);
    }
}



inline void relax(int v, int x, int d) {
    if (dp[v][x] > d) {
        dp[v][x] = d;
        pq.push(mp(d, mp(v, x)));
    }
}


double solve(int N, int M, int kk, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> A) {
    n = N; m = M; k = min(K-1, kk); h = H;

    for (int i=0; i<n; i++) adj[i].clear();
    fill(seen, seen+n+1, 0);

    while (pq.size()) pq.pop();

    p2[0] = 1.0;
    for (int i=1; i<K; i++) p2[i] = p2[i-1]/2.0;

    for (int j=0; j<=k; j++) for (int i=0; i<n; i++) dp[i][j] = INF;

    for (int i=0; i<m; i++) {
        u = x[i]; v = y[i]; w = c[i];

        adj[u].pb(mp(v, w));
        adj[v].pb(mp(u, w));
    }

    for (int i=0; i<n; i++) arr[i] = A[i];

    DFS(0);
    
    relax(h, k, 0);

    while (pq.size()) {
        auto cur = pq.top(); pq.pop();

        v = cur.S.F;
        tmp = cur.S.S;

        if (dp[v][tmp] < cur.F) continue;
        if ((arr[v] == 0 && seen[v]) || v == 0) return cur.F;

        for (auto cur:adj[v]) {
            int u = cur.F;
            double w = cur.S;
            
            if (!seen[u]) continue;
            
            relax(u, tmp, dp[v][tmp] + w*p2[k-tmp]);

            if (arr[v] == 2 && k > 0) relax(u, tmp-1, dp[v][tmp] + w*p2[k-tmp+1]);
        }
    }
    
    return -1;
}

Compilation message

cyberland.cpp: In function 'void DFS(int)':
cyberland.cpp:35:24: warning: unused variable 'w' [-Wunused-variable]
   35 |         int u = cur.F, w = cur.S;
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 31324 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 31324 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 31324 KB Double -2.14748e+09 violates the range [-1, 1e+18]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 66096 KB Correct.
2 Incorrect 23 ms 32344 KB Double -1.93831e+09 violates the range [-1, 1e+18]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 31580 KB Double -2.8463e+08 violates the range [-1, 1e+18]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 31580 KB Correct.
2 Correct 22 ms 32348 KB Correct.
3 Correct 62 ms 79224 KB Correct.
4 Correct 20 ms 36688 KB Correct.
5 Incorrect 23 ms 32208 KB Double -1.92822e+09 violates the range [-1, 1e+18]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 31604 KB Correct.
2 Correct 9 ms 31580 KB Correct.
3 Incorrect 60 ms 91560 KB Wrong Answer.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 32252 KB Wrong Answer.
2 Halted 0 ms 0 KB -