답안 #694869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
694869 2023-02-04T11:04:25 Z jiahng 악어의 지하 도시 (IOI11_crocodile) C++14
46 / 100
13 ms 13268 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
#define DEBUG 0

bool spec[maxn];
vpi adj[maxn];
vi adj2[maxn];
ll dist0[maxn], distK[maxn];
int cnt[maxn];
int N;
bool ok(int X){
    FOR(i,0,N-1) adj2[i].clear();
    vi v;
    FOR(i,0,N-1){
        cnt[i] = 0;
        aFOR(j, adj[i]){
            if (dist0[i] + j.s + distK[j.f] <= X){
                if (spec[j.f]) cnt[i]++;
                adj2[j.f].pb(i); 
            }
        }
        if (cnt[i] >= 2) v.pb(i);
    }

    /*
    vi v;
    FOR(i,0,N-1){
        cnt[i] = 0;
        aFOR(j, adj2[i]) if (spec[j]) cnt[i]++;
        if (cnt[i] >= 2) v.pb(i);
    }
    */

    while (!v.empty()){
        int x = v.back(); v.pop_back();
        if (x == 0) return 1;
        aFOR(i, adj2[x]){
            cnt[i]++; if (cnt[i] == 2) v.pb(i);
        }
    }
    return 0;
}


int32_t travel_plan(int32_t N, int32_t M, int32_t R[][2], int32_t L[], int32_t K, int32_t P[])
{
    ::N = N;
    FOR(i,0,M-1){
        adj[R[i][0]].pb(pi(R[i][1], L[i]));
        adj[R[i][1]].pb(pi(R[i][0], L[i]));
    }
    FOR(i,0,K-1) spec[P[i]] = 1;
    // dijkstra from 0
    priority_queue <pi,vector <pi>, greater <pi> > pq;
    mem(dist0,-1);
    pq.push(pi(0,0)); dist0[0] = 0;
    while (!pq.empty()){
        pi cur = pq.top(); pq.pop();

        if (dist0[cur.s] != cur.f) continue;

        aFOR(i, adj[cur.s]){
            if (dist0[i.f] == -1 || dist0[i.f] > cur.f + i.s){
                dist0[i.f] = cur.f + i.s;
                pq.push({dist0[i.f], i.f});
            }
        }
    }
    
    // multisource dijkstra from exits
    mem(distK,-1);
    FOR(i,0,K-1){
        pq.push(pi(0, P[i])); distK[P[i]] = 0;
    }
    
    while (!pq.empty()){
        pi cur = pq.top(); pq.pop();

        if (distK[cur.s] != cur.f) continue;

        aFOR(i, adj[cur.s]){
            if (distK[i.f] == -1 || distK[i.f] > cur.f + i.s){
                distK[i.f] = cur.f + i.s;
                pq.push({distK[i.f], i.f});
            }
        }
    }

    if (DEBUG){
        FOR(i,0,N-1) cout << dist0[i] << ' ';
        cout << '\n';
        FOR(i,0,N-1) cout << distK[i] << ' ';
        cout << '\n';
    }
    ll l = -1, r = 1e18;
    while (l + 1 < r){
        ll m = (l + r) >> 1;
        if (ok(m)) r = m;
        else l = m;
    }
    return r;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12764 KB Output is correct
2 Correct 7 ms 12756 KB Output is correct
3 Correct 10 ms 12884 KB Output is correct
4 Correct 10 ms 12916 KB Output is correct
5 Correct 9 ms 12884 KB Output is correct
6 Correct 8 ms 12884 KB Output is correct
7 Correct 10 ms 12884 KB Output is correct
8 Correct 9 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12764 KB Output is correct
2 Correct 7 ms 12756 KB Output is correct
3 Correct 10 ms 12884 KB Output is correct
4 Correct 10 ms 12916 KB Output is correct
5 Correct 9 ms 12884 KB Output is correct
6 Correct 8 ms 12884 KB Output is correct
7 Correct 10 ms 12884 KB Output is correct
8 Correct 9 ms 12884 KB Output is correct
9 Correct 13 ms 13268 KB Output is correct
10 Incorrect 7 ms 12884 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12764 KB Output is correct
2 Correct 7 ms 12756 KB Output is correct
3 Correct 10 ms 12884 KB Output is correct
4 Correct 10 ms 12916 KB Output is correct
5 Correct 9 ms 12884 KB Output is correct
6 Correct 8 ms 12884 KB Output is correct
7 Correct 10 ms 12884 KB Output is correct
8 Correct 9 ms 12884 KB Output is correct
9 Correct 13 ms 13268 KB Output is correct
10 Incorrect 7 ms 12884 KB Output isn't correct
11 Halted 0 ms 0 KB -