답안 #919776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919776 2024-02-01T15:52:49 Z Maaxle 꿈 (IOI13_dreaming) C++17
47 / 100
59 ms 20052 KB
#include "dreaming.h"
#include <bits/stdc++.h>

#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 60)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map 
#define pqueue priority_queue
#define ptr(A) shared_ptr<A>

using namespace std;

struct Edge {
    ll node, wth;
};

struct Component {
    ll diameter_length;
    ll rep_max;
};
bool operator < (const Component& a, const Component& b) { return a.rep_max < b.rep_max; }

vector<vector<Edge>> adj;
vector<bool> memo;
pqueue<Component> comp;

ll max_d; ll max_i;
void find_furthest (ll i, ll from, ll cnt) {
    memo[i] = 1;

    if (max_d < cnt) {
        max_d = cnt;
        max_i = i;
    }

    for (auto& k : adj[i]) {
        if (k.node != from) 
            find_furthest(k.node, i, cnt + k.wth);
    }
}

vector<pair<ll, ll>> path;
ll dlength;

ll fill_path (ll i, ll from, ll cnt) {
    path[i].first = cnt;

    ll maxi = 0;
    for (auto& k : adj[i]) {
        if (k.node != from) {
            maxi = max(maxi, k.wth + fill_path(k.node, i, cnt + k.wth));
        }
    }
    path[i].second = maxi;
    dlength = max(dlength, path[i].first + path[i].second);
    return maxi;
}

ll min_abs, rep_i;
void find_rep(ll i, ll from) {
    if (path[i].first + path[i].second == dlength) {
        if (abs(path[i].first - path[i].second) < min_abs) {
            min_abs = abs(path[i].first - path[i].second);
            rep_i = i;
        }
    }

    for (auto& k : adj[i]) {
        if (k.node != from)
            find_rep(k.node, i);
    }
}


Component find_representative(ll i) {
    max_d = -1;
    find_furthest(i, i, 0);
    
    max_d = -1;
    dlength = -1;
    fill_path(max_i, max_i, 0);

    min_abs = INF64;
    find_rep(i, i);

    // cout << dlength << ' ' << max(path[rep_i].first, path[rep_i].second) << '\n';
    return {dlength, max(path[rep_i].first, path[rep_i].second)};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    adj.resize(N);
    memo.resize(N);
    path.resize(N);
    
    range(i, 0, M) {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }

    range(i, 0, N) {
        if (!memo[i]) {
            // cout << "** " << i << '\n';
            comp.push(find_representative(i));
        }
    }

    while (comp.size() > 1) {
        Component c1 = comp.top(); comp.pop();
        Component c2 = comp.top(); comp.pop();
        comp.push({max({c1.rep_max + c2.rep_max + L, c1.diameter_length, c2.diameter_length}), max(c1.rep_max, c2.rep_max) + L});
    }

    return comp.top().diameter_length;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 17504 KB Output is correct
2 Correct 37 ms 17460 KB Output is correct
3 Correct 24 ms 11860 KB Output is correct
4 Correct 6 ms 2904 KB Output is correct
5 Correct 5 ms 1880 KB Output is correct
6 Correct 10 ms 4444 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 18 ms 7000 KB Output is correct
9 Correct 23 ms 9304 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 34 ms 12528 KB Output is correct
12 Correct 45 ms 15440 KB Output is correct
13 Correct 1 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 17504 KB Output is correct
2 Correct 37 ms 17460 KB Output is correct
3 Correct 24 ms 11860 KB Output is correct
4 Correct 6 ms 2904 KB Output is correct
5 Correct 5 ms 1880 KB Output is correct
6 Correct 10 ms 4444 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 18 ms 7000 KB Output is correct
9 Correct 23 ms 9304 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 34 ms 12528 KB Output is correct
12 Correct 45 ms 15440 KB Output is correct
13 Correct 1 ms 752 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 39 ms 17744 KB Output is correct
40 Correct 40 ms 17500 KB Output is correct
41 Correct 24 ms 11860 KB Output is correct
42 Correct 6 ms 2904 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 1 ms 548 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 44 ms 13240 KB Output is correct
58 Correct 43 ms 12620 KB Output is correct
59 Correct 44 ms 12372 KB Output is correct
60 Correct 44 ms 12368 KB Output is correct
61 Correct 46 ms 12376 KB Output is correct
62 Correct 43 ms 12368 KB Output is correct
63 Correct 38 ms 11856 KB Output is correct
64 Correct 39 ms 12044 KB Output is correct
65 Correct 42 ms 12320 KB Output is correct
66 Correct 48 ms 12528 KB Output is correct
67 Correct 43 ms 12376 KB Output is correct
68 Correct 44 ms 12520 KB Output is correct
69 Correct 46 ms 12624 KB Output is correct
70 Correct 59 ms 13096 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 2 ms 600 KB Output is correct
73 Correct 2 ms 856 KB Output is correct
74 Correct 2 ms 600 KB Output is correct
75 Correct 2 ms 600 KB Output is correct
76 Correct 2 ms 600 KB Output is correct
77 Correct 2 ms 600 KB Output is correct
78 Correct 2 ms 600 KB Output is correct
79 Correct 2 ms 600 KB Output is correct
80 Correct 42 ms 12368 KB Output is correct
81 Correct 44 ms 12376 KB Output is correct
82 Correct 43 ms 12372 KB Output is correct
83 Correct 40 ms 12368 KB Output is correct
84 Correct 2 ms 856 KB Output is correct
85 Correct 2 ms 600 KB Output is correct
86 Correct 1 ms 696 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 600 KB Output is correct
89 Correct 1 ms 600 KB Output is correct
90 Correct 1 ms 600 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 0 ms 344 KB Output is correct
98 Correct 0 ms 344 KB Output is correct
99 Correct 0 ms 344 KB Output is correct
100 Correct 0 ms 344 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 344 KB Output is correct
103 Correct 0 ms 344 KB Output is correct
104 Correct 5 ms 1880 KB Output is correct
105 Correct 10 ms 4440 KB Output is correct
106 Correct 0 ms 344 KB Output is correct
107 Correct 18 ms 7000 KB Output is correct
108 Correct 25 ms 9296 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 36 ms 12368 KB Output is correct
111 Correct 39 ms 14928 KB Output is correct
112 Correct 1 ms 600 KB Output is correct
113 Correct 59 ms 20052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 7896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 17504 KB Output is correct
2 Correct 37 ms 17460 KB Output is correct
3 Correct 24 ms 11860 KB Output is correct
4 Correct 6 ms 2904 KB Output is correct
5 Correct 5 ms 1880 KB Output is correct
6 Correct 10 ms 4444 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 18 ms 7000 KB Output is correct
9 Correct 23 ms 9304 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 34 ms 12528 KB Output is correct
12 Correct 45 ms 15440 KB Output is correct
13 Correct 1 ms 752 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 39 ms 17744 KB Output is correct
40 Correct 40 ms 17500 KB Output is correct
41 Correct 24 ms 11860 KB Output is correct
42 Correct 6 ms 2904 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 1 ms 548 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 44 ms 13240 KB Output is correct
58 Correct 43 ms 12620 KB Output is correct
59 Correct 44 ms 12372 KB Output is correct
60 Correct 44 ms 12368 KB Output is correct
61 Correct 46 ms 12376 KB Output is correct
62 Correct 43 ms 12368 KB Output is correct
63 Correct 38 ms 11856 KB Output is correct
64 Correct 39 ms 12044 KB Output is correct
65 Correct 42 ms 12320 KB Output is correct
66 Correct 48 ms 12528 KB Output is correct
67 Correct 43 ms 12376 KB Output is correct
68 Correct 44 ms 12520 KB Output is correct
69 Correct 46 ms 12624 KB Output is correct
70 Correct 59 ms 13096 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 2 ms 600 KB Output is correct
73 Correct 2 ms 856 KB Output is correct
74 Correct 2 ms 600 KB Output is correct
75 Correct 2 ms 600 KB Output is correct
76 Correct 2 ms 600 KB Output is correct
77 Correct 2 ms 600 KB Output is correct
78 Correct 2 ms 600 KB Output is correct
79 Correct 2 ms 600 KB Output is correct
80 Correct 42 ms 12368 KB Output is correct
81 Correct 44 ms 12376 KB Output is correct
82 Correct 43 ms 12372 KB Output is correct
83 Correct 40 ms 12368 KB Output is correct
84 Correct 2 ms 856 KB Output is correct
85 Correct 2 ms 600 KB Output is correct
86 Correct 1 ms 696 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 600 KB Output is correct
89 Correct 1 ms 600 KB Output is correct
90 Correct 1 ms 600 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 0 ms 344 KB Output is correct
98 Correct 0 ms 344 KB Output is correct
99 Correct 0 ms 344 KB Output is correct
100 Correct 0 ms 344 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 344 KB Output is correct
103 Correct 0 ms 344 KB Output is correct
104 Correct 5 ms 1880 KB Output is correct
105 Correct 10 ms 4440 KB Output is correct
106 Correct 0 ms 344 KB Output is correct
107 Correct 18 ms 7000 KB Output is correct
108 Correct 25 ms 9296 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 36 ms 12368 KB Output is correct
111 Correct 39 ms 14928 KB Output is correct
112 Correct 1 ms 600 KB Output is correct
113 Correct 59 ms 20052 KB Output is correct
114 Incorrect 24 ms 7896 KB Output isn't correct
115 Halted 0 ms 0 KB -