답안 #1005454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005454 2024-06-22T13:05:31 Z c2zi6 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
312 ms 71364 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "crocodile.h"

struct DS {
    ll min1, min2;
    DS() {
        min1 = 1e18;
        min2 = 1e18;
    }
    void add(ll x) {
        if (x <= min1) {
            min2 = min1;
            min1 = x;
        } else if (x <= min2) {
            min2 = x;
        }
    }
};
bool operator<(const DS& a, const DS& b) {
    return (a.min2 != b.min2) ? (a.min2 < b.min2) : (a.min1 < b.min1);
}
typedef pair<DS, int> DATA;

int n, m;
VVPI gp;
VI exits;

int solve() {
    priority_queue<DATA, vector<DATA>, greater<DATA>> pq;
    vector<DS> dist(n);
    vector<bool> vis(n);
    for (int u : exits) {
        dist[u].min1 = dist[u].min2 = 0;
        pq.push({dist[u], u});
    }
    while (pq.size()) {
        int u = pq.top().ss;
        pq.pop();
        if (vis[u]) continue;
        vis[u] = true;
        for (auto[v, w] : gp[u]) {
            DS cur = dist[v];
            cur.add(dist[u].min2 + w);
            if (cur < dist[v]) {
                dist[v] = cur;
                pq.push({dist[v], v});
            }
        }
    }
    return dist[0].min2;
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    n = N;
    m = M;
    gp = VVPI(n);
    rep(i, m) {
        int u = R[i][0];
        int v = R[i][1];
        int w = L[i];
        gp[u].pb({v, w});
        gp[v].pb({u, w});
    }
    rep(i, K) {
        exits.pb(P[i]);
    }
    return solve();
}




Compilation message

crocodile.cpp: In function 'int solve()':
crocodile.cpp:71:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   71 |         for (auto[v, w] : gp[u]) {
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4696 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4696 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 249 ms 61636 KB Output is correct
17 Correct 60 ms 19396 KB Output is correct
18 Correct 75 ms 22216 KB Output is correct
19 Correct 312 ms 71364 KB Output is correct
20 Correct 162 ms 46932 KB Output is correct
21 Correct 27 ms 10316 KB Output is correct
22 Correct 195 ms 45876 KB Output is correct