답안 #775801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775801 2023-07-07T03:24:23 Z NoLove 악어의 지하 도시 (IOI11_crocodile) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
const int INF = 1e18;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    // process input
    vector<pair<int, int>> adj[N];
    for (int i = 0; i < M; i++) {
        adj[R[i][0]].push_back({R[i][1], L[i]});
        adj[R[i][1]].push_back({R[i][0], L[i]});
    }
//    // {T2, T1} (T1 < T2)
    pair<int, int> dp[N + 1]; // dp[i]: minumum time from node i to escape
    memset(dp, 0x3f3f3f, N*sizeof(dp[0]));
    // dijkstra
    set<pair<int, int>> q;
    for (int i = 0; i < K; i++) {
        q.insert({0, P[i]});
        dp[P[i]] = {0, 0};
    }
    while (q.size()) {
        int v = q.begin()->second;
        int c = q.begin()->first;
        q.erase(q.begin());
        if (c != dp[v].first) continue;
        for (auto[u, cost] : adj[v]) {
            if (dp[v].first + cost < dp[u].first) {
                if (dp[v].first + cost < dp[u].second) {
                    dp[u].first = dp[u].second;
                    dp[u].second = dp[v].first + cost;
                } else {
                    dp[u].first = dp[v].first + cost;
                }
                q.insert({dp[u].first, u});
            }
        }
    }
    return dp[0].first;
}

Compilation message

crocodile.cpp:2:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    2 | const int INF = 1e18;
      |                 ^~~~
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:6:5: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
    6 |     vector<pair<int, int>> adj[N];
      |     ^~~~~~
      |     std::vector
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from crocodile.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note: 'std::vector' declared here
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
crocodile.cpp:6:12: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
    6 |     vector<pair<int, int>> adj[N];
      |            ^~~~
      |            std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from crocodile.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
crocodile.cpp:6:17: error: expected primary-expression before 'int'
    6 |     vector<pair<int, int>> adj[N];
      |                 ^~~
crocodile.cpp:8:9: error: 'adj' was not declared in this scope
    8 |         adj[R[i][0]].push_back({R[i][1], L[i]});
      |         ^~~
crocodile.cpp:12:10: error: expected primary-expression before 'int'
   12 |     pair<int, int> dp[N + 1]; // dp[i]: minumum time from node i to escape
      |          ^~~
crocodile.cpp:13:12: error: 'dp' was not declared in this scope
   13 |     memset(dp, 0x3f3f3f, N*sizeof(dp[0]));
      |            ^~
crocodile.cpp:15:5: error: 'set' was not declared in this scope; did you mean 'std::set'?
   15 |     set<pair<int, int>> q;
      |     ^~~
      |     std::set
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from crocodile.cpp:1:
/usr/include/c++/10/bits/stl_set.h:94:11: note: 'std::set' declared here
   94 |     class set
      |           ^~~
crocodile.cpp:15:14: error: expected primary-expression before 'int'
   15 |     set<pair<int, int>> q;
      |              ^~~
crocodile.cpp:17:9: error: 'q' was not declared in this scope
   17 |         q.insert({0, P[i]});
      |         ^
crocodile.cpp:20:12: error: 'q' was not declared in this scope
   20 |     while (q.size()) {
      |            ^
crocodile.cpp:25:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         for (auto[u, cost] : adj[v]) {
      |                  ^
crocodile.cpp:25:30: error: 'adj' was not declared in this scope
   25 |         for (auto[u, cost] : adj[v]) {
      |                              ^~~