답안 #595016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595016 2022-07-13T09:04:49 Z pakhomovee 꿈 (IOI13_dreaming) C++17
24 / 100
1000 ms 23448 KB
#include "dreaming.h"
#include <vector>
#include <map>
#include <deque>
#include <iostream>

using namespace std;

const int maxn = 1e5;
const int inf = 2e9;
bool used[maxn];

map<int, int> dst(int v, vector<vector<pair<int, int>>> &g) {
    map<int, int> d;
    deque<int> q;
    q.push_back(v);
    d[v] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        for (auto [u, w] : g[v]) {
            if (!d.count(u)) {
                d[u] = d[v] + w;
                q.push_back(u);
            }
        }
    }
    return d;
}

pair<int, int> goFar(int v, vector<vector<pair<int, int>>> &g) {
    auto d1 = dst(v, g);
    int best = v;
    for (auto [u, x] : d1) {
        if (d1[best] < x) {
            best = u;
        }
        used[u] = true;
    }
    return { best, d1[best] };
}

pair<int, int> findDiam(int v, vector<vector<pair<int, int>>> &g) {
    int leafe = goFar(v, g).first;
    int best = goFar(leafe, g).first;
    int best1 = goFar(best, g).first;
    return { best, best1 };
}

int findDiamLen(int v, vector<vector<pair<int, int>>> &g) {
    int leafe = goFar(v, g).first;
    int best = goFar(leafe, g).first;
    return goFar(best, g).second;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<vector<pair<int, int>>> g(N);
    for (int i = 0; i < M; ++i) {
        int u = A[i], v = B[i];
        g[u].push_back({ v, T[i] });
        g[v].push_back({ u, T[i] });
    }
    vector<pair<int, int>> dims;
    for (int i = 0; i < N; ++i) {
        if (!used[i]) {
            dims.push_back(findDiam(i, g));
        }
    }
    pair<int, int> curr = dims[0];
    /*cout << "OUT" << endl;
    for (auto [x, y] : dims) {
        cout << x << ' ' << y << endl;
    }*/
    for (int i = 1; i < dims.size(); ++i) {
        auto d1 = dst(curr.first, g);
        auto d2 = dst(curr.second, g);
        auto d3 = dst(dims[i].first, g);
        auto d4 = dst(dims[i].second, g);
        pair<int, int> cand;
        int b1 = inf;
        for (auto [u, l] : d1) {
            if (b1 > max(l, d2[u])) {
                b1 = max(l, d2[u]);
                cand.first = u;
            }
        }
        b1 = inf;
        for (auto [u, l] : d3) {
            if (b1 > max(l, d4[u])) {
                b1 = max(l, d4[u]);
                cand.second = u;
            }
        }
        //cout << "UNITE " << cand.first << ' ' << cand.second << endl;
        g[cand.first].push_back({ cand.second, L });
        g[cand.second].push_back({ cand.first, L });
        curr = findDiam(cand.first, g);
    }
    return findDiamLen(0, g);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 1; i < dims.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 833 ms 20432 KB Output is correct
2 Correct 842 ms 20460 KB Output is correct
3 Correct 522 ms 13656 KB Output is correct
4 Correct 80 ms 3404 KB Output is correct
5 Correct 57 ms 2516 KB Output is correct
6 Correct 141 ms 4716 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 346 ms 9172 KB Output is correct
9 Correct 389 ms 11380 KB Output is correct
10 Correct 3 ms 440 KB Output is correct
11 Correct 620 ms 15936 KB Output is correct
12 Correct 788 ms 18004 KB Output is correct
13 Correct 5 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 833 ms 20432 KB Output is correct
2 Correct 842 ms 20460 KB Output is correct
3 Correct 522 ms 13656 KB Output is correct
4 Correct 80 ms 3404 KB Output is correct
5 Correct 57 ms 2516 KB Output is correct
6 Correct 141 ms 4716 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 346 ms 9172 KB Output is correct
9 Correct 389 ms 11380 KB Output is correct
10 Correct 3 ms 440 KB Output is correct
11 Correct 620 ms 15936 KB Output is correct
12 Correct 788 ms 18004 KB Output is correct
13 Correct 5 ms 520 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 834 ms 20456 KB Output is correct
40 Correct 813 ms 20396 KB Output is correct
41 Correct 475 ms 13644 KB Output is correct
42 Correct 77 ms 3256 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Execution timed out 1086 ms 23448 KB Time limit exceeded
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 6156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 156 ms 648 KB Output is correct
27 Correct 667 ms 744 KB Output is correct
28 Execution timed out 1086 ms 952 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 833 ms 20432 KB Output is correct
2 Correct 842 ms 20460 KB Output is correct
3 Correct 522 ms 13656 KB Output is correct
4 Correct 80 ms 3404 KB Output is correct
5 Correct 57 ms 2516 KB Output is correct
6 Correct 141 ms 4716 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 346 ms 9172 KB Output is correct
9 Correct 389 ms 11380 KB Output is correct
10 Correct 3 ms 440 KB Output is correct
11 Correct 620 ms 15936 KB Output is correct
12 Correct 788 ms 18004 KB Output is correct
13 Correct 5 ms 520 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 312 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 308 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 834 ms 20456 KB Output is correct
40 Correct 813 ms 20396 KB Output is correct
41 Correct 475 ms 13644 KB Output is correct
42 Correct 77 ms 3256 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Execution timed out 1086 ms 23448 KB Time limit exceeded
58 Halted 0 ms 0 KB -