답안 #557206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557206 2022-05-04T21:09:40 Z Olympia 꿈 (IOI13_dreaming) C++17
47 / 100
456 ms 24220 KB
#include <iostream>
#include <vector>
#include "dreaming.h"
#include <climits>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
vector<int> a, b, w;
vector<vector<int> > adj;
map<pair<int,int>,int> myMap;
vector<bool> hasVisited;
vector<int> parent;
pair<int,int> find_farthest_node (int x, bool undo) {
    queue<pair<int,int> > q;
    q.push(make_pair(x, 0));
    hasVisited[x] = true;
    parent[x] = -1;
    vector<int> nodes;
    vector<pair<int,int> > vec;
    while (!q.empty()) {
        pair<int,int> p = q.front();
        nodes.push_back(p.first);
        vec.push_back(make_pair(p.second, p.first));
        q.pop();
        for (int j: adj[p.first]) {
            if (!hasVisited[j]) {
                q.push(make_pair(j, p.second + myMap[make_pair(j, p.first)]));
                parent[j] = p.first;
                hasVisited[j] = true;
            }
        }
    }
 
    if (undo) {
        for (int j: nodes) {
            hasVisited[j] = false;
        }
    }
    sort(vec.begin(), vec.end());
    return vec.back(); //first distance, then node
}
int travelTime (int N, int M, int L, int A[], int B[], int W[]) {
    a.resize(M), b.resize(M), w.resize(M), adj.resize(N), parent.resize(N);
    for (int i = 0; i < M; i++) {
        a[i] = A[i], b[i] = B[i], w[i] = W[i];
        myMap[make_pair(a[i], b[i])] = w[i];
        myMap[make_pair(b[i], a[i])] = w[i];
        adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
    }
    hasVisited.assign(N, false);
    vector<int> paths;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (!hasVisited[i]) {
            int x = find_farthest_node(i, true).second;
            int y = find_farthest_node(x, false).second;
            vector<int> nodes;
            int val = y;
            while (val != -1) {
                nodes.push_back(val);
                val = parent[val];
            }
            int sum = 0;
            for (int j = 1; j < (int) nodes.size(); j++) {
                sum += myMap[make_pair(nodes[j], nodes[j - 1])];
            }
            ans = max(ans, sum);
            int c = 0;
            int myMin = INT_MAX;
            int best = 0;
            for (int j = 1; j < (int)nodes.size(); j++) {
                c += myMap[make_pair(nodes[j], nodes[j - 1])];
                if (max(c, sum - c) < myMin) {
                    myMin = max(c, sum - c);
                    best = nodes[j];
                }
            }
            if (nodes.size() == 1) {
                myMin = 0;
            }
            paths.push_back(myMin);
        }
    }
    sort(paths.begin(), paths.end());
    //cout << paths.size() << '\n';
    if (paths.size() == 1) {
        ans = max(ans, paths[0]);
    } else if (paths.size() == 2) {
        ans = max(paths.back() + paths[paths.size() - 2] + L, ans);
    } else {
        ans = max(paths.back() + paths[paths.size() - 2] + 2 * L, ans);
    }
    return ans;
}
 
/*
int main() {
   int N = 12;
   int M = 8;
   int L = 2;
   int A[M], B[M], T[M];
   A[0] = 0, A[1] = 8, A[2] = 2, A[3] = 5, A[4] = 5, A[5] = 1, A[6] = 1, A[7] = 10;
   B[0] = 8, B[1] = 2, B[2] = 7, B[3] = 11, B[4] = 1, B[5] = 3, B[6] = 9, B[7] = 6;
   T[0] = 4, T[1] = 2, T[2] = 4, T[3] = 3, T[4] = 7, T[5] = 1, T[6] = 5, T[7] = 3;
   cout << travelTime(N, M, L, A, B, T);
}
*/

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:71:17: warning: variable 'best' set but not used [-Wunused-but-set-variable]
   71 |             int best = 0;
      |                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 21528 KB Output is correct
2 Correct 312 ms 21516 KB Output is correct
3 Correct 168 ms 14232 KB Output is correct
4 Correct 23 ms 3540 KB Output is correct
5 Correct 18 ms 2588 KB Output is correct
6 Correct 40 ms 5144 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 129 ms 9628 KB Output is correct
9 Correct 174 ms 12144 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 245 ms 16524 KB Output is correct
12 Correct 330 ms 19336 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 288 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 212 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 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 308 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 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 484 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 304 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 21528 KB Output is correct
2 Correct 312 ms 21516 KB Output is correct
3 Correct 168 ms 14232 KB Output is correct
4 Correct 23 ms 3540 KB Output is correct
5 Correct 18 ms 2588 KB Output is correct
6 Correct 40 ms 5144 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 129 ms 9628 KB Output is correct
9 Correct 174 ms 12144 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 245 ms 16524 KB Output is correct
12 Correct 330 ms 19336 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 288 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 212 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 308 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 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 484 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 304 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 280 ms 21784 KB Output is correct
40 Correct 356 ms 21708 KB Output is correct
41 Correct 153 ms 14444 KB Output is correct
42 Correct 22 ms 3616 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 308 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 304 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 308 KB Output is correct
51 Correct 1 ms 304 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 Correct 328 ms 24032 KB Output is correct
58 Correct 386 ms 22804 KB Output is correct
59 Correct 354 ms 23652 KB Output is correct
60 Correct 386 ms 22872 KB Output is correct
61 Correct 329 ms 23732 KB Output is correct
62 Correct 355 ms 22876 KB Output is correct
63 Correct 341 ms 24084 KB Output is correct
64 Correct 386 ms 24212 KB Output is correct
65 Correct 365 ms 23760 KB Output is correct
66 Correct 375 ms 24220 KB Output is correct
67 Correct 364 ms 23732 KB Output is correct
68 Correct 361 ms 23660 KB Output is correct
69 Correct 346 ms 22988 KB Output is correct
70 Correct 372 ms 22896 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 5 ms 980 KB Output is correct
73 Correct 6 ms 1000 KB Output is correct
74 Correct 5 ms 980 KB Output is correct
75 Correct 5 ms 1016 KB Output is correct
76 Correct 4 ms 980 KB Output is correct
77 Correct 5 ms 980 KB Output is correct
78 Correct 5 ms 980 KB Output is correct
79 Correct 5 ms 964 KB Output is correct
80 Correct 367 ms 23600 KB Output is correct
81 Correct 392 ms 23564 KB Output is correct
82 Correct 334 ms 23832 KB Output is correct
83 Correct 415 ms 24084 KB Output is correct
84 Correct 4 ms 852 KB Output is correct
85 Correct 3 ms 724 KB Output is correct
86 Correct 4 ms 852 KB Output is correct
87 Correct 4 ms 852 KB Output is correct
88 Correct 4 ms 868 KB Output is correct
89 Correct 4 ms 852 KB Output is correct
90 Correct 4 ms 852 KB Output is correct
91 Correct 4 ms 980 KB Output is correct
92 Correct 5 ms 852 KB Output is correct
93 Correct 4 ms 864 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 340 KB Output is correct
100 Correct 1 ms 340 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 1 ms 308 KB Output is correct
103 Correct 1 ms 340 KB Output is correct
104 Correct 18 ms 2588 KB Output is correct
105 Correct 39 ms 5116 KB Output is correct
106 Correct 1 ms 340 KB Output is correct
107 Correct 98 ms 9540 KB Output is correct
108 Correct 175 ms 12240 KB Output is correct
109 Correct 2 ms 340 KB Output is correct
110 Correct 256 ms 16636 KB Output is correct
111 Correct 322 ms 19444 KB Output is correct
112 Correct 2 ms 468 KB Output is correct
113 Correct 456 ms 23704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 10104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 288 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 212 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 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 308 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 304 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 484 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 304 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 304 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 4 ms 868 KB Output is correct
29 Incorrect 2 ms 468 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 21528 KB Output is correct
2 Correct 312 ms 21516 KB Output is correct
3 Correct 168 ms 14232 KB Output is correct
4 Correct 23 ms 3540 KB Output is correct
5 Correct 18 ms 2588 KB Output is correct
6 Correct 40 ms 5144 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 129 ms 9628 KB Output is correct
9 Correct 174 ms 12144 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 245 ms 16524 KB Output is correct
12 Correct 330 ms 19336 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 288 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 212 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 308 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 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 484 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 304 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 280 ms 21784 KB Output is correct
40 Correct 356 ms 21708 KB Output is correct
41 Correct 153 ms 14444 KB Output is correct
42 Correct 22 ms 3616 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 308 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 304 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 308 KB Output is correct
51 Correct 1 ms 304 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 Correct 328 ms 24032 KB Output is correct
58 Correct 386 ms 22804 KB Output is correct
59 Correct 354 ms 23652 KB Output is correct
60 Correct 386 ms 22872 KB Output is correct
61 Correct 329 ms 23732 KB Output is correct
62 Correct 355 ms 22876 KB Output is correct
63 Correct 341 ms 24084 KB Output is correct
64 Correct 386 ms 24212 KB Output is correct
65 Correct 365 ms 23760 KB Output is correct
66 Correct 375 ms 24220 KB Output is correct
67 Correct 364 ms 23732 KB Output is correct
68 Correct 361 ms 23660 KB Output is correct
69 Correct 346 ms 22988 KB Output is correct
70 Correct 372 ms 22896 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 5 ms 980 KB Output is correct
73 Correct 6 ms 1000 KB Output is correct
74 Correct 5 ms 980 KB Output is correct
75 Correct 5 ms 1016 KB Output is correct
76 Correct 4 ms 980 KB Output is correct
77 Correct 5 ms 980 KB Output is correct
78 Correct 5 ms 980 KB Output is correct
79 Correct 5 ms 964 KB Output is correct
80 Correct 367 ms 23600 KB Output is correct
81 Correct 392 ms 23564 KB Output is correct
82 Correct 334 ms 23832 KB Output is correct
83 Correct 415 ms 24084 KB Output is correct
84 Correct 4 ms 852 KB Output is correct
85 Correct 3 ms 724 KB Output is correct
86 Correct 4 ms 852 KB Output is correct
87 Correct 4 ms 852 KB Output is correct
88 Correct 4 ms 868 KB Output is correct
89 Correct 4 ms 852 KB Output is correct
90 Correct 4 ms 852 KB Output is correct
91 Correct 4 ms 980 KB Output is correct
92 Correct 5 ms 852 KB Output is correct
93 Correct 4 ms 864 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 340 KB Output is correct
100 Correct 1 ms 340 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 1 ms 308 KB Output is correct
103 Correct 1 ms 340 KB Output is correct
104 Correct 18 ms 2588 KB Output is correct
105 Correct 39 ms 5116 KB Output is correct
106 Correct 1 ms 340 KB Output is correct
107 Correct 98 ms 9540 KB Output is correct
108 Correct 175 ms 12240 KB Output is correct
109 Correct 2 ms 340 KB Output is correct
110 Correct 256 ms 16636 KB Output is correct
111 Correct 322 ms 19444 KB Output is correct
112 Correct 2 ms 468 KB Output is correct
113 Correct 456 ms 23704 KB Output is correct
114 Incorrect 93 ms 10104 KB Output isn't correct
115 Halted 0 ms 0 KB -