답안 #249741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249741 2020-07-15T16:26:13 Z eohomegrownapps 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
739 ms 97500 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<ll,ll>>> adjlist; //val,node
ll n,k;
vector<ll> exits; //k of them
ll INF = 1e18;
ll dijkstra(){
    //source is 0
    vector<pair<ll,ll>> distances(n,{INF,INF}); //second then first
    priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>,ll>>,greater<pair<pair<ll,ll>,ll>>> pq;
    //second,first
    for (ll i = 0; i<k; i++){
        distances[exits[i]]={0,0};
        pq.push({{0,0},exits[i]});
    }
    while (pq.size()>0){
        auto f = pq.top();
        pq.pop();
        /*cout<<"======\n";
        cout<<f.second<<'\n';
        for (auto p : distances){
            cout<<p.first<<" "<<p.second<<'\n';
        }*/
        //cout<<"check: "<<distances[f.second].first<<" "<<distances[f.second].second<<", "<<f.first.first<<" "<<f.first.second<<'\n';
        if (distances[f.second]<f.first){
            continue; //can't remember this condition
        }
        for (auto p : adjlist[f.second]){
            ll dist = p.first;
            ll node = p.second;
            ll newval = distances[f.second].first+dist;
            //cout<<newval<<'\n';
            if (newval<=distances[node].second){
                distances[node].first=distances[node].second;
                distances[node].second=newval;
                pq.push({distances[node],node});
            } else if (newval<distances[node].first){
                distances[node].first=newval;
                pq.push({distances[node],node});
            }
        }
    }
    return distances[0].first;
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    n=N;k=K;
    adjlist.resize(n);
    for (ll i = 0; i<M; i++){
        adjlist[R[i][0]].push_back({L[i],R[i][1]});
        adjlist[R[i][1]].push_back({L[i],R[i][0]});
    }
    exits = vector<ll>(P,P+k);
    return dijkstra();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 4 ms 1024 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 4 ms 1024 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 628 ms 85260 KB Output is correct
17 Correct 114 ms 20848 KB Output is correct
18 Correct 143 ms 23276 KB Output is correct
19 Correct 739 ms 97500 KB Output is correct
20 Correct 347 ms 65784 KB Output is correct
21 Correct 51 ms 9076 KB Output is correct
22 Correct 378 ms 63272 KB Output is correct