답안 #250978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250978 2020-07-19T17:30:00 Z A02 꿈 (IOI13_dreaming) C++14
47 / 100
522 ms 29816 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;

pair<long long, long long> calc_centre(int start, vector<vector<pair<long long, long long> > > &adjacent){




    queue<long long> to_visit;
    to_visit.push(start);

    map<long long, long long> distances1;
    distances1[start] = 0;

    long long longest_distance = 0;
    long long endpoint = start;

    while (!to_visit.empty()){

            long long current = to_visit.front();
            if (longest_distance < distances1[current]){
                longest_distance = distances1[current];
                endpoint = current;
            }

            to_visit.pop();

            for (int j = 0; j < adjacent[current].size(); j++){
                if (distances1.find(adjacent[current][j].first) == distances1.end()){
                    distances1[adjacent[current][j].first] = distances1[current] + adjacent[current][j].second;
                    to_visit.push(adjacent[current][j].first);
                }
            }
    }


    map<long long, long long> distances;
    map<long long, long long> parent;
    parent[endpoint] = endpoint;

    to_visit.push(endpoint);

    longest_distance = 0;
    long long startpoint = endpoint;

    while (!to_visit.empty()){

            long long current = to_visit.front();

            if (longest_distance < distances[current]){
                longest_distance = distances[current];
                startpoint = current;
            }

            to_visit.pop();

            for (long long j = 0; j < adjacent[current].size(); j++){
                if (distances.find(adjacent[current][j].first) == distances.end()){
                    distances[adjacent[current][j].first] = distances[current] + adjacent[current][j].second;
                    to_visit.push(adjacent[current][j].first);
                    parent[adjacent[current][j].first] = current;
                }
            }
    }

    long long radius = longest_distance;

    long long current = startpoint;

    long long left_distance = longest_distance;
    long long right_distance = 0;

    while (current != endpoint){
        radius = min(radius, max(left_distance, right_distance));

        current = parent[current];
        left_distance = distances[current];
        right_distance = longest_distance - left_distance;

    }

    return make_pair(radius, longest_distance);

}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {

    vector<vector<pair<long long, long long> > > adjacent (N, vector<pair<long long, long long> > ());

    for (int i = 0; i < M; i++){
        adjacent[A[i]].push_back(make_pair(B[i], T[i]));
        adjacent[B[i]].push_back(make_pair(A[i], T[i]));
    }

    vector<long long> region (N, -1);
    long long current_region = 0;
    vector<pair<long long, long long> > radii;

    for (int i = 0; i < N; i++){
        if (region[i] == -1){

            radii.push_back(calc_centre(i, adjacent));

            queue<long long> to_visit;
            to_visit.push(i);

            while (!to_visit.empty()){

                long long current = to_visit.front();
                to_visit.pop();
                region[current] = current_region;

                for (long long j = 0; j < adjacent[current].size(); j++){
                    if (region[adjacent[current][j].first] == -1){
                        to_visit.push(adjacent[current][j].first);
                    }
                }

            }


            current_region++;
        }

    }

    while (radii.size() > 1){

        pair<long long, long long> a1 = radii[radii.size() - 1];
        pair<long long, long long> a2 = radii[radii.size() - 2];
        radii.pop_back();
        radii.pop_back();

        long long r1 = (min(max(a1.first, a2.first + L), max(a2.first, a1.first + L)));
        radii.push_back(make_pair(r1, max(a1.second, max(a2.second, a1.first + a2.first + L))));

    }


    return radii[0].second;
}

Compilation message

dreaming.cpp: In function 'std::pair<long long int, long long int> calc_centre(int, std::vector<std::vector<std::pair<long long int, long long int> > >&)':
dreaming.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < adjacent[current].size(); j++){
                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:64:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (long long j = 0; j < adjacent[current].size(); j++){
                                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:120:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (long long j = 0; j < adjacent[current].size(); j++){
                                       ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 26744 KB Output is correct
2 Correct 397 ms 26780 KB Output is correct
3 Correct 226 ms 17912 KB Output is correct
4 Correct 36 ms 4224 KB Output is correct
5 Correct 29 ms 2304 KB Output is correct
6 Correct 58 ms 6264 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 126 ms 9208 KB Output is correct
9 Correct 169 ms 13308 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 271 ms 17016 KB Output is correct
12 Correct 351 ms 22008 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 26744 KB Output is correct
2 Correct 397 ms 26780 KB Output is correct
3 Correct 226 ms 17912 KB Output is correct
4 Correct 36 ms 4224 KB Output is correct
5 Correct 29 ms 2304 KB Output is correct
6 Correct 58 ms 6264 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 126 ms 9208 KB Output is correct
9 Correct 169 ms 13308 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 271 ms 17016 KB Output is correct
12 Correct 351 ms 22008 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 380 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 26744 KB Output is correct
2 Correct 397 ms 26780 KB Output is correct
3 Correct 226 ms 17912 KB Output is correct
4 Correct 36 ms 4224 KB Output is correct
5 Correct 29 ms 2304 KB Output is correct
6 Correct 58 ms 6264 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 126 ms 9208 KB Output is correct
9 Correct 169 ms 13308 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 271 ms 17016 KB Output is correct
12 Correct 351 ms 22008 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 380 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 420 ms 26768 KB Output is correct
40 Correct 370 ms 26744 KB Output is correct
41 Correct 208 ms 17912 KB Output is correct
42 Correct 37 ms 4344 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 0 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 476 ms 29432 KB Output is correct
58 Correct 486 ms 21992 KB Output is correct
59 Correct 411 ms 27348 KB Output is correct
60 Correct 452 ms 20728 KB Output is correct
61 Correct 448 ms 27444 KB Output is correct
62 Correct 522 ms 23288 KB Output is correct
63 Correct 431 ms 29688 KB Output is correct
64 Correct 434 ms 29704 KB Output is correct
65 Correct 425 ms 29688 KB Output is correct
66 Correct 431 ms 29816 KB Output is correct
67 Correct 418 ms 28024 KB Output is correct
68 Correct 400 ms 27744 KB Output is correct
69 Correct 357 ms 22196 KB Output is correct
70 Correct 363 ms 22028 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 6 ms 1024 KB Output is correct
73 Correct 6 ms 1152 KB Output is correct
74 Correct 8 ms 1152 KB Output is correct
75 Correct 6 ms 1024 KB Output is correct
76 Correct 6 ms 1152 KB Output is correct
77 Correct 7 ms 1152 KB Output is correct
78 Correct 6 ms 976 KB Output is correct
79 Correct 8 ms 1280 KB Output is correct
80 Correct 394 ms 23996 KB Output is correct
81 Correct 430 ms 24184 KB Output is correct
82 Correct 384 ms 27384 KB Output is correct
83 Correct 429 ms 29432 KB Output is correct
84 Correct 4 ms 768 KB Output is correct
85 Correct 4 ms 896 KB Output is correct
86 Correct 5 ms 768 KB Output is correct
87 Correct 5 ms 896 KB Output is correct
88 Correct 5 ms 904 KB Output is correct
89 Correct 5 ms 896 KB Output is correct
90 Correct 5 ms 896 KB Output is correct
91 Correct 6 ms 1152 KB Output is correct
92 Correct 6 ms 1024 KB Output is correct
93 Correct 6 ms 896 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 1 ms 384 KB Output is correct
98 Correct 0 ms 384 KB Output is correct
99 Correct 0 ms 384 KB Output is correct
100 Correct 0 ms 384 KB Output is correct
101 Correct 0 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 0 ms 384 KB Output is correct
104 Correct 25 ms 2304 KB Output is correct
105 Correct 59 ms 6264 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 129 ms 9212 KB Output is correct
108 Correct 171 ms 13304 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 272 ms 17016 KB Output is correct
111 Correct 398 ms 22012 KB Output is correct
112 Correct 3 ms 512 KB Output is correct
113 Correct 476 ms 29688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 7152 KB Output is correct
2 Correct 60 ms 7188 KB Output is correct
3 Correct 81 ms 7156 KB Output is correct
4 Incorrect 61 ms 7156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 26744 KB Output is correct
2 Correct 397 ms 26780 KB Output is correct
3 Correct 226 ms 17912 KB Output is correct
4 Correct 36 ms 4224 KB Output is correct
5 Correct 29 ms 2304 KB Output is correct
6 Correct 58 ms 6264 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 126 ms 9208 KB Output is correct
9 Correct 169 ms 13308 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 271 ms 17016 KB Output is correct
12 Correct 351 ms 22008 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 4 ms 640 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Incorrect 0 ms 384 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 26744 KB Output is correct
2 Correct 397 ms 26780 KB Output is correct
3 Correct 226 ms 17912 KB Output is correct
4 Correct 36 ms 4224 KB Output is correct
5 Correct 29 ms 2304 KB Output is correct
6 Correct 58 ms 6264 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 126 ms 9208 KB Output is correct
9 Correct 169 ms 13308 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 271 ms 17016 KB Output is correct
12 Correct 351 ms 22008 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 380 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 420 ms 26768 KB Output is correct
40 Correct 370 ms 26744 KB Output is correct
41 Correct 208 ms 17912 KB Output is correct
42 Correct 37 ms 4344 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 0 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 476 ms 29432 KB Output is correct
58 Correct 486 ms 21992 KB Output is correct
59 Correct 411 ms 27348 KB Output is correct
60 Correct 452 ms 20728 KB Output is correct
61 Correct 448 ms 27444 KB Output is correct
62 Correct 522 ms 23288 KB Output is correct
63 Correct 431 ms 29688 KB Output is correct
64 Correct 434 ms 29704 KB Output is correct
65 Correct 425 ms 29688 KB Output is correct
66 Correct 431 ms 29816 KB Output is correct
67 Correct 418 ms 28024 KB Output is correct
68 Correct 400 ms 27744 KB Output is correct
69 Correct 357 ms 22196 KB Output is correct
70 Correct 363 ms 22028 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 6 ms 1024 KB Output is correct
73 Correct 6 ms 1152 KB Output is correct
74 Correct 8 ms 1152 KB Output is correct
75 Correct 6 ms 1024 KB Output is correct
76 Correct 6 ms 1152 KB Output is correct
77 Correct 7 ms 1152 KB Output is correct
78 Correct 6 ms 976 KB Output is correct
79 Correct 8 ms 1280 KB Output is correct
80 Correct 394 ms 23996 KB Output is correct
81 Correct 430 ms 24184 KB Output is correct
82 Correct 384 ms 27384 KB Output is correct
83 Correct 429 ms 29432 KB Output is correct
84 Correct 4 ms 768 KB Output is correct
85 Correct 4 ms 896 KB Output is correct
86 Correct 5 ms 768 KB Output is correct
87 Correct 5 ms 896 KB Output is correct
88 Correct 5 ms 904 KB Output is correct
89 Correct 5 ms 896 KB Output is correct
90 Correct 5 ms 896 KB Output is correct
91 Correct 6 ms 1152 KB Output is correct
92 Correct 6 ms 1024 KB Output is correct
93 Correct 6 ms 896 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 0 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 1 ms 384 KB Output is correct
98 Correct 0 ms 384 KB Output is correct
99 Correct 0 ms 384 KB Output is correct
100 Correct 0 ms 384 KB Output is correct
101 Correct 0 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 0 ms 384 KB Output is correct
104 Correct 25 ms 2304 KB Output is correct
105 Correct 59 ms 6264 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 129 ms 9212 KB Output is correct
108 Correct 171 ms 13304 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 272 ms 17016 KB Output is correct
111 Correct 398 ms 22012 KB Output is correct
112 Correct 3 ms 512 KB Output is correct
113 Correct 476 ms 29688 KB Output is correct
114 Correct 66 ms 7152 KB Output is correct
115 Correct 60 ms 7188 KB Output is correct
116 Correct 81 ms 7156 KB Output is correct
117 Incorrect 61 ms 7156 KB Output isn't correct
118 Halted 0 ms 0 KB -