답안 #637146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637146 2022-08-31T16:23:21 Z ghostwriter 악어의 지하 도시 (IOI11_crocodile) C++14
89 / 100
501 ms 48944 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
struct Vertex {
    int u, Min, Min1;
    Vertex() {}
    Vertex(int u, int Min, int Min1) : u(u), Min(Min), Min1(Min1) {}
};
struct cmp {
    bool operator()(Vertex a, Vertex b) {
        return a.Min1 > b.Min1;
    }
};
const int oo = 1e9 + 1;
const int NMAX = 1e5 + 1;
pi d[NMAX];
vpi adj[NMAX];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    FOR(i, 0, N - 1) d[i] = {oo, oo};
    FOR(i, 0, M - 1) {
        int u = R[i][0], v = R[i][1], w = L[i];
        adj[u].pb({v, w});
        adj[v].pb({u, w});
    }
    priority_queue<Vertex, vector<Vertex>, cmp> pq;
    FOR(i, 0, K - 1) {
        int u = P[i];
        d[u] = {0, 0};
        pq.push(Vertex(u, 0, 0));
    }
    WHILE(!pq.empty()) {
        Vertex cur = pq.top();
        pq.pop();
        int u = cur.u, Min = cur.Min, Min1 = cur.Min1;
        if (Min1 > d[u].nd) continue;
        EACH(j, adj[u]) {
            int v = j.st, w = j.nd;
            if (d[v].nd > Min1 + w) {
                d[v].nd = Min1 + w;
                if (d[v].st > d[v].nd) swap(d[v].st, d[v].nd);
                pq.push(Vertex(v, d[v].st, d[v].nd));
            }
        }
    }
    return d[0].nd;
}
/*
5 4 3
0 1 2
0 2 3
3 2 1
2 4 4
1
3
4
7
 
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1
3
14
*/

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
crocodile.cpp:53:5: note: in expansion of macro 'FOR'
   53 |     FOR(i, 0, N - 1) d[i] = {oo, oo};
      |     ^~~
crocodile.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
crocodile.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(i, 0, M - 1) {
      |     ^~~
crocodile.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
crocodile.cpp:60:5: note: in expansion of macro 'FOR'
   60 |     FOR(i, 0, K - 1) {
      |     ^~~
crocodile.cpp:28:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   28 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
crocodile.cpp:70:9: note: in expansion of macro 'EACH'
   70 |         EACH(j, adj[u]) {
      |         ^~~~
crocodile.cpp:68:24: warning: unused variable 'Min' [-Wunused-variable]
   68 |         int u = cur.u, Min = cur.Min, Min1 = cur.Min1;
      |                        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2656 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2656 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 4 ms 3028 KB Output is correct
13 Correct 4 ms 3028 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 3 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2656 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 4 ms 3028 KB Output is correct
13 Correct 4 ms 3028 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 380 ms 43136 KB Output is correct
17 Correct 87 ms 12116 KB Output is correct
18 Correct 93 ms 13452 KB Output is correct
19 Correct 501 ms 48944 KB Output is correct
20 Correct 231 ms 36652 KB Output is correct
21 Correct 41 ms 6732 KB Output is correct
22 Incorrect 275 ms 32232 KB Output isn't correct
23 Halted 0 ms 0 KB -