답안 #729049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729049 2023-04-23T12:51:33 Z grogu Shortcut (IOI16_shortcut) C++14
0 / 100
26 ms 47216 KB
#include "shortcut.h"
#include <bits/stdc++.h>
#define endl '\n'
#define here cerr<<"=========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define ll long long
#define pb push_back
#define popb pop_back
#define all(a_) a_.begin(),a_.end()
#define pll pair<ll,ll>
#define sc second
#define fi first
#define llinf 1000000000000000LL
#define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;}

using namespace std;
#define maxn 2000005
ll n,c,tsz;
vector<pll> g[maxn];
ll dis[maxn];
ll naj(ll x){
    for(ll i = 0;i<=tsz;i++) dis[i] = llinf;
    dis[x] = 0;
    priority_queue<pll> pq;
    pq.push({0,x});
    while(pq.size()){
        ll u = pq.top().sc;
        ll cur = -pq.top().fi;
        pq.pop();
        if(cur!=dis[u]) continue;
        for(pll p : g[u]){
            ll s = p.fi;
            ll w = p.sc;
            if(cur+w<dis[s]){
                dis[s] = cur+w;
                pq.push({-dis[s],s});
            }
        }
    }
    ll ans = 1;
    for(ll i = 1;i<=tsz;i++) if(dis[i]>dis[ans]) ans = i;
    return ans;
}
ll find_shortcut(int N, vector<int> L, vector<int> D, int C)
{
    n = N;
    tsz = n;
    c = C;
    for(ll i = 1;i<n;i++){
        g[i].pb({i+1,L[i-1]});
        g[i+1].pb({i,L[i-1]});
    }
    for(ll i = 1;i<=n;i++) if(D[i-1]){
        g[i].pb({++tsz,D[i-1]});
        g[tsz].pb({i,D[i-1]});
    }
    ll ans = llinf;
    for(ll i = 1;i<=n;i++){
        for(ll j = i+1;j<=n;j++){
            g[i].pb({j,c});
            g[j].pb({i,c});
            ll x = naj(1);
            ll y = naj(x);
            ans = min(ans,dis[y]);
            g[i].popb();
            g[j].popb();
        }
    }
    return ans;
}
/**
4 10
10 20 20
0 40 0 30
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47216 KB n = 4, 80 is a correct answer
2 Incorrect 26 ms 47188 KB n = 9, incorrect answer: jury 110 vs contestant 100
3 Halted 0 ms 0 KB -