답안 #250983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250983 2020-07-19T17:59:11 Z A02 꿈 (IOI13_dreaming) C++14
47 / 100
492 ms 28792 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;
    distances[endpoint] = 0;

    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:33:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < adjacent[current].size(); j++){
                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:63: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:119: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 373 ms 25848 KB Output is correct
2 Correct 372 ms 25864 KB Output is correct
3 Correct 216 ms 16888 KB Output is correct
4 Correct 35 ms 4096 KB Output is correct
5 Correct 25 ms 2176 KB Output is correct
6 Correct 61 ms 6008 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 129 ms 8724 KB Output is correct
9 Correct 169 ms 12664 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 283 ms 16060 KB Output is correct
12 Correct 340 ms 20984 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 25848 KB Output is correct
2 Correct 372 ms 25864 KB Output is correct
3 Correct 216 ms 16888 KB Output is correct
4 Correct 35 ms 4096 KB Output is correct
5 Correct 25 ms 2176 KB Output is correct
6 Correct 61 ms 6008 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 129 ms 8724 KB Output is correct
9 Correct 169 ms 12664 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 283 ms 16060 KB Output is correct
12 Correct 340 ms 20984 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 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 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 25848 KB Output is correct
2 Correct 372 ms 25864 KB Output is correct
3 Correct 216 ms 16888 KB Output is correct
4 Correct 35 ms 4096 KB Output is correct
5 Correct 25 ms 2176 KB Output is correct
6 Correct 61 ms 6008 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 129 ms 8724 KB Output is correct
9 Correct 169 ms 12664 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 283 ms 16060 KB Output is correct
12 Correct 340 ms 20984 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 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 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 393 ms 25788 KB Output is correct
40 Correct 429 ms 25744 KB Output is correct
41 Correct 238 ms 16888 KB Output is correct
42 Correct 37 ms 4096 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 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 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 427 ms 28280 KB Output is correct
58 Correct 392 ms 21112 KB Output is correct
59 Correct 407 ms 26360 KB Output is correct
60 Correct 375 ms 19704 KB Output is correct
61 Correct 394 ms 26488 KB Output is correct
62 Correct 391 ms 22264 KB Output is correct
63 Correct 428 ms 28664 KB Output is correct
64 Correct 436 ms 28792 KB Output is correct
65 Correct 427 ms 28664 KB Output is correct
66 Correct 437 ms 28664 KB Output is correct
67 Correct 416 ms 26872 KB Output is correct
68 Correct 437 ms 26616 KB Output is correct
69 Correct 389 ms 21020 KB Output is correct
70 Correct 359 ms 20948 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 6 ms 896 KB Output is correct
73 Correct 6 ms 1024 KB Output is correct
74 Correct 7 ms 1152 KB Output is correct
75 Correct 6 ms 896 KB Output is correct
76 Correct 6 ms 1024 KB Output is correct
77 Correct 6 ms 1152 KB Output is correct
78 Correct 6 ms 976 KB Output is correct
79 Correct 6 ms 1024 KB Output is correct
80 Correct 362 ms 23100 KB Output is correct
81 Correct 385 ms 23032 KB Output is correct
82 Correct 397 ms 26396 KB Output is correct
83 Correct 413 ms 28408 KB Output is correct
84 Correct 4 ms 768 KB Output is correct
85 Correct 4 ms 896 KB Output is correct
86 Correct 4 ms 768 KB Output is correct
87 Correct 6 ms 800 KB Output is correct
88 Correct 5 ms 776 KB Output is correct
89 Correct 5 ms 768 KB Output is correct
90 Correct 5 ms 768 KB Output is correct
91 Correct 6 ms 1024 KB Output is correct
92 Correct 6 ms 896 KB Output is correct
93 Correct 5 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 0 ms 384 KB Output is correct
97 Correct 0 ms 384 KB Output is correct
98 Correct 1 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 2176 KB Output is correct
105 Correct 61 ms 6008 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 131 ms 8632 KB Output is correct
108 Correct 166 ms 12664 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 265 ms 15992 KB Output is correct
111 Correct 320 ms 21036 KB Output is correct
112 Correct 2 ms 512 KB Output is correct
113 Correct 492 ms 28792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 6768 KB Output is correct
2 Correct 54 ms 6876 KB Output is correct
3 Correct 54 ms 6772 KB Output is correct
4 Incorrect 55 ms 6900 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 25848 KB Output is correct
2 Correct 372 ms 25864 KB Output is correct
3 Correct 216 ms 16888 KB Output is correct
4 Correct 35 ms 4096 KB Output is correct
5 Correct 25 ms 2176 KB Output is correct
6 Correct 61 ms 6008 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 129 ms 8724 KB Output is correct
9 Correct 169 ms 12664 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 283 ms 16060 KB Output is correct
12 Correct 340 ms 20984 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Incorrect 2 ms 384 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 25848 KB Output is correct
2 Correct 372 ms 25864 KB Output is correct
3 Correct 216 ms 16888 KB Output is correct
4 Correct 35 ms 4096 KB Output is correct
5 Correct 25 ms 2176 KB Output is correct
6 Correct 61 ms 6008 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 129 ms 8724 KB Output is correct
9 Correct 169 ms 12664 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 283 ms 16060 KB Output is correct
12 Correct 340 ms 20984 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 0 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 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 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 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 393 ms 25788 KB Output is correct
40 Correct 429 ms 25744 KB Output is correct
41 Correct 238 ms 16888 KB Output is correct
42 Correct 37 ms 4096 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 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 0 ms 384 KB Output is correct
48 Correct 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 0 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 0 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 0 ms 384 KB Output is correct
57 Correct 427 ms 28280 KB Output is correct
58 Correct 392 ms 21112 KB Output is correct
59 Correct 407 ms 26360 KB Output is correct
60 Correct 375 ms 19704 KB Output is correct
61 Correct 394 ms 26488 KB Output is correct
62 Correct 391 ms 22264 KB Output is correct
63 Correct 428 ms 28664 KB Output is correct
64 Correct 436 ms 28792 KB Output is correct
65 Correct 427 ms 28664 KB Output is correct
66 Correct 437 ms 28664 KB Output is correct
67 Correct 416 ms 26872 KB Output is correct
68 Correct 437 ms 26616 KB Output is correct
69 Correct 389 ms 21020 KB Output is correct
70 Correct 359 ms 20948 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 6 ms 896 KB Output is correct
73 Correct 6 ms 1024 KB Output is correct
74 Correct 7 ms 1152 KB Output is correct
75 Correct 6 ms 896 KB Output is correct
76 Correct 6 ms 1024 KB Output is correct
77 Correct 6 ms 1152 KB Output is correct
78 Correct 6 ms 976 KB Output is correct
79 Correct 6 ms 1024 KB Output is correct
80 Correct 362 ms 23100 KB Output is correct
81 Correct 385 ms 23032 KB Output is correct
82 Correct 397 ms 26396 KB Output is correct
83 Correct 413 ms 28408 KB Output is correct
84 Correct 4 ms 768 KB Output is correct
85 Correct 4 ms 896 KB Output is correct
86 Correct 4 ms 768 KB Output is correct
87 Correct 6 ms 800 KB Output is correct
88 Correct 5 ms 776 KB Output is correct
89 Correct 5 ms 768 KB Output is correct
90 Correct 5 ms 768 KB Output is correct
91 Correct 6 ms 1024 KB Output is correct
92 Correct 6 ms 896 KB Output is correct
93 Correct 5 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 0 ms 384 KB Output is correct
97 Correct 0 ms 384 KB Output is correct
98 Correct 1 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 2176 KB Output is correct
105 Correct 61 ms 6008 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 131 ms 8632 KB Output is correct
108 Correct 166 ms 12664 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 265 ms 15992 KB Output is correct
111 Correct 320 ms 21036 KB Output is correct
112 Correct 2 ms 512 KB Output is correct
113 Correct 492 ms 28792 KB Output is correct
114 Correct 56 ms 6768 KB Output is correct
115 Correct 54 ms 6876 KB Output is correct
116 Correct 54 ms 6772 KB Output is correct
117 Incorrect 55 ms 6900 KB Output isn't correct
118 Halted 0 ms 0 KB -