답안 #127631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127631 2019-07-09T17:54:38 Z dolphingarlic 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
789 ms 72728 KB
#include "crocodile.h"
#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MOD 1000000007
#define MAXN 100001
using namespace std;

vector<int> exits;
vector<pair<int, int>> graph[MAXN];
int visited[MAXN];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    FOR(i, 0, M) {
        graph[R[i][0]].push_back({R[i][1], L[i]});
        graph[R[i][1]].push_back({R[i][0], L[i]});
    }
    FOR(i, 0, K) exits.push_back(P[i]);
    fill(visited, visited + MAXN, 0);
    priority_queue<pair<int, int>> pq;  // Distance from an exit
    for (int i : exits) {
        pq.push({0, i});
        visited[i] = 1;
    }

    while (!pq.empty()) {
        int curr_node = pq.top().second, curr_cost = pq.top().first;
        pq.pop();

        if (visited[curr_node] == 0) {
            visited[curr_node]++;
        } else if (visited[curr_node] == 1) {
            if (curr_node == 0) return -curr_cost;
            visited[curr_node]++;
            for (pair<int, int> i : graph[curr_node]) pq.push({curr_cost - i.second, i.first});
        }
    }
}

Compilation message

crocodile.cpp:3:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
 #pragma GCC Optimize("O3")
 
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 4 ms 3064 KB Output is correct
3 Correct 5 ms 3064 KB Output is correct
4 Correct 5 ms 3192 KB Output is correct
5 Correct 6 ms 3192 KB Output is correct
6 Correct 5 ms 3192 KB Output is correct
7 Correct 5 ms 3168 KB Output is correct
8 Correct 5 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 4 ms 3064 KB Output is correct
3 Correct 5 ms 3064 KB Output is correct
4 Correct 5 ms 3192 KB Output is correct
5 Correct 6 ms 3192 KB Output is correct
6 Correct 5 ms 3192 KB Output is correct
7 Correct 5 ms 3168 KB Output is correct
8 Correct 5 ms 3192 KB Output is correct
9 Correct 8 ms 3448 KB Output is correct
10 Correct 5 ms 3064 KB Output is correct
11 Correct 6 ms 3320 KB Output is correct
12 Correct 11 ms 3960 KB Output is correct
13 Correct 10 ms 3960 KB Output is correct
14 Correct 6 ms 3192 KB Output is correct
15 Correct 6 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 4 ms 3064 KB Output is correct
3 Correct 5 ms 3064 KB Output is correct
4 Correct 5 ms 3192 KB Output is correct
5 Correct 6 ms 3192 KB Output is correct
6 Correct 5 ms 3192 KB Output is correct
7 Correct 5 ms 3168 KB Output is correct
8 Correct 5 ms 3192 KB Output is correct
9 Correct 8 ms 3448 KB Output is correct
10 Correct 5 ms 3064 KB Output is correct
11 Correct 6 ms 3320 KB Output is correct
12 Correct 11 ms 3960 KB Output is correct
13 Correct 10 ms 3960 KB Output is correct
14 Correct 6 ms 3192 KB Output is correct
15 Correct 6 ms 3192 KB Output is correct
16 Correct 682 ms 72728 KB Output is correct
17 Correct 113 ms 13364 KB Output is correct
18 Correct 123 ms 14840 KB Output is correct
19 Correct 789 ms 67168 KB Output is correct
20 Correct 417 ms 66516 KB Output is correct
21 Correct 59 ms 7928 KB Output is correct
22 Correct 672 ms 46812 KB Output is correct