답안 #960594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960594 2024-04-10T16:33:19 Z TAhmed33 가장 긴 여행 (IOI23_longesttrip) C++17
60 / 100
126 ms 2068 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
int cnt;
vector <int> tree[256];
bool vis[256];
vector <int> x;
int p[256];
set <int> unvis;
void dfs (int pos) {
    vis[pos] = 1; x.push_back(pos); unvis.erase(pos);
    while (true) {
        vector <int> t; for (auto i : unvis) t.push_back(i);
        int l = 0, r = (int)t.size() - 1, ans = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector <int> g;
            for (int i = 0; i <= mid; i++) g.push_back(t[i]);
          	cnt++; assert(cnt <= 3000);
            if (are_connected({pos}, g)) {
                r = mid - 1; ans = mid; 
            } else {
                l = mid + 1;
            }
        }
        if (ans == -1) break;
        tree[pos].push_back(t[ans]);
        p[t[ans]] = pos;
        dfs(t[ans]);
    }
}
int get (int x) {
    if (tree[x].empty()) return x;
    return get(tree[x][0]);
}
vector <int> longest_trip (int n, int d) {
  	cnt = 0;
    unvis.clear(); for (int i = 0; i < n; i++) unvis.insert(i);
    for (int i = 0; i < n; i++) tree[i].clear();
    memset(p, -1, sizeof(p));
    memset(vis, 0, sizeof(vis));
    x.clear(); dfs(0);
    if (!unvis.empty()) {
        vector <int> ret = x;
        for (int i = 0; i < n; i++) {
            if (!vis[i]) {
                x.clear(); dfs(i);
                if ((int)x.size() > (int)ret.size()) ret = x;
            }
        }
        return ret;
    }
    int pos = -1;
    for (int i = 0; i < n; i++) {
        if ((int)tree[i].size() == 2) {
            pos = i;
        }
    }
    if (pos == -1) return x;
    int u = get(tree[pos][0]), v = get(tree[pos][1]);
    if (p[pos] != -1 && !are_connected({p[pos]}, {u})) {
        swap(u, v); swap(tree[pos][0], tree[pos][1]);
    }
    u = tree[pos][0], v = tree[pos][1];
    while (!x.empty() && x.back() != p[pos]) x.pop_back();
    vector <int> l;
    while (true) {
        l.push_back(u);
        if (tree[u].empty()) break;
        u = tree[u][0];
    }
    reverse(l.begin(), l.end());
    for (auto i : l) x.push_back(i);
    x.push_back(pos);
    while (true) {
        x.push_back(v);
        if (tree[v].empty()) break;
        v = tree[v][0];
    }
    return x;   
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 17 ms 1064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 12 ms 344 KB Output is correct
3 Correct 23 ms 600 KB Output is correct
4 Correct 35 ms 976 KB Output is correct
5 Correct 50 ms 1032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 12 ms 344 KB Output is correct
3 Correct 23 ms 600 KB Output is correct
4 Correct 36 ms 1396 KB Output is correct
5 Correct 46 ms 1564 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 10 ms 344 KB Output is correct
8 Correct 24 ms 600 KB Output is correct
9 Correct 30 ms 488 KB Output is correct
10 Correct 43 ms 1352 KB Output is correct
11 Correct 47 ms 1076 KB Output is correct
12 Correct 41 ms 1328 KB Output is correct
13 Correct 48 ms 1556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 13 ms 344 KB Output is correct
3 Correct 22 ms 600 KB Output is correct
4 Correct 33 ms 976 KB Output is correct
5 Correct 47 ms 1540 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 29 ms 600 KB Output is correct
10 Correct 37 ms 1272 KB Output is correct
11 Correct 48 ms 1288 KB Output is correct
12 Correct 46 ms 1788 KB Output is correct
13 Correct 51 ms 1064 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 16 ms 600 KB Output is correct
17 Correct 20 ms 600 KB Output is correct
18 Correct 19 ms 344 KB Output is correct
19 Correct 32 ms 856 KB Output is correct
20 Correct 28 ms 608 KB Output is correct
21 Correct 50 ms 916 KB Output is correct
22 Correct 53 ms 1324 KB Output is correct
23 Correct 43 ms 1524 KB Output is correct
24 Correct 43 ms 976 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 16 ms 344 KB Output is correct
28 Correct 16 ms 344 KB Output is correct
29 Correct 16 ms 344 KB Output is correct
30 Correct 28 ms 700 KB Output is correct
31 Correct 41 ms 704 KB Output is correct
32 Correct 45 ms 1212 KB Output is correct
33 Correct 33 ms 600 KB Output is correct
34 Correct 42 ms 880 KB Output is correct
35 Correct 50 ms 600 KB Output is correct
36 Correct 52 ms 1592 KB Output is correct
37 Correct 68 ms 1548 KB Output is correct
38 Correct 99 ms 1068 KB Output is correct
39 Correct 116 ms 1112 KB Output is correct
40 Correct 108 ms 1536 KB Output is correct
41 Correct 120 ms 1312 KB Output is correct
42 Correct 124 ms 1776 KB Output is correct
43 Correct 121 ms 1020 KB Output is correct
44 Correct 110 ms 1824 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 10 ms 344 KB Output is correct
47 Correct 13 ms 344 KB Output is correct
48 Correct 13 ms 344 KB Output is correct
49 Correct 11 ms 344 KB Output is correct
50 Correct 26 ms 444 KB Output is correct
51 Correct 38 ms 964 KB Output is correct
52 Correct 39 ms 960 KB Output is correct
53 Correct 32 ms 856 KB Output is correct
54 Correct 30 ms 856 KB Output is correct
55 Correct 37 ms 1112 KB Output is correct
56 Correct 47 ms 1336 KB Output is correct
57 Correct 53 ms 1364 KB Output is correct
58 Correct 67 ms 1076 KB Output is correct
59 Correct 73 ms 1808 KB Output is correct
60 Correct 74 ms 1068 KB Output is correct
61 Correct 99 ms 1352 KB Output is correct
62 Correct 81 ms 1248 KB Output is correct
63 Correct 91 ms 2068 KB Output is correct
64 Correct 85 ms 1764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 9 ms 344 KB Output is correct
3 Correct 22 ms 600 KB Output is correct
4 Partially correct 30 ms 1116 KB Output is partially correct
5 Partially correct 47 ms 1000 KB Output is partially correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 12 ms 344 KB Output is correct
8 Correct 21 ms 856 KB Output is correct
9 Partially correct 32 ms 600 KB Output is partially correct
10 Partially correct 49 ms 1308 KB Output is partially correct
11 Partially correct 40 ms 1016 KB Output is partially correct
12 Partially correct 43 ms 1520 KB Output is partially correct
13 Partially correct 47 ms 1116 KB Output is partially correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 16 ms 600 KB Output is correct
17 Correct 21 ms 344 KB Output is correct
18 Correct 21 ms 344 KB Output is correct
19 Partially correct 31 ms 600 KB Output is partially correct
20 Partially correct 30 ms 1112 KB Output is partially correct
21 Correct 8 ms 344 KB Output is correct
22 Correct 11 ms 344 KB Output is correct
23 Correct 17 ms 504 KB Output is correct
24 Correct 15 ms 344 KB Output is correct
25 Correct 18 ms 344 KB Output is correct
26 Correct 30 ms 444 KB Output is correct
27 Partially correct 50 ms 960 KB Output is partially correct
28 Partially correct 51 ms 708 KB Output is partially correct
29 Partially correct 35 ms 600 KB Output is partially correct
30 Partially correct 43 ms 1472 KB Output is partially correct
31 Partially correct 46 ms 600 KB Output is partially correct
32 Correct 7 ms 344 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 12 ms 344 KB Output is correct
35 Correct 14 ms 344 KB Output is correct
36 Correct 12 ms 344 KB Output is correct
37 Correct 26 ms 704 KB Output is correct
38 Partially correct 32 ms 960 KB Output is partially correct
39 Partially correct 35 ms 1212 KB Output is partially correct
40 Partially correct 26 ms 600 KB Output is partially correct
41 Partially correct 37 ms 860 KB Output is partially correct
42 Partially correct 35 ms 1112 KB Output is partially correct
43 Partially correct 44 ms 1492 KB Output is partially correct
44 Partially correct 42 ms 1784 KB Output is partially correct
45 Partially correct 46 ms 692 KB Output is partially correct
46 Partially correct 40 ms 1524 KB Output is partially correct
47 Partially correct 47 ms 1396 KB Output is partially correct
48 Partially correct 74 ms 1536 KB Output is partially correct
49 Partially correct 92 ms 1364 KB Output is partially correct
50 Partially correct 112 ms 1380 KB Output is partially correct
51 Partially correct 118 ms 1508 KB Output is partially correct
52 Partially correct 116 ms 1092 KB Output is partially correct
53 Partially correct 112 ms 1348 KB Output is partially correct
54 Partially correct 122 ms 1512 KB Output is partially correct
55 Partially correct 121 ms 1080 KB Output is partially correct
56 Partially correct 81 ms 1520 KB Output is partially correct
57 Partially correct 90 ms 1080 KB Output is partially correct
58 Partially correct 101 ms 1528 KB Output is partially correct
59 Partially correct 114 ms 1092 KB Output is partially correct
60 Partially correct 117 ms 1084 KB Output is partially correct
61 Partially correct 126 ms 1332 KB Output is partially correct
62 Partially correct 42 ms 1012 KB Output is partially correct
63 Partially correct 57 ms 1784 KB Output is partially correct
64 Partially correct 64 ms 1828 KB Output is partially correct
65 Partially correct 72 ms 1096 KB Output is partially correct
66 Partially correct 71 ms 1280 KB Output is partially correct
67 Partially correct 98 ms 1380 KB Output is partially correct
68 Partially correct 75 ms 1808 KB Output is partially correct
69 Partially correct 84 ms 1116 KB Output is partially correct
70 Partially correct 94 ms 1236 KB Output is partially correct
71 Partially correct 62 ms 1816 KB Output is partially correct
72 Partially correct 69 ms 1516 KB Output is partially correct
73 Partially correct 86 ms 1572 KB Output is partially correct
74 Partially correct 87 ms 1332 KB Output is partially correct
75 Partially correct 100 ms 1172 KB Output is partially correct
76 Partially correct 83 ms 1524 KB Output is partially correct
77 Partially correct 59 ms 1372 KB Output is partially correct
78 Partially correct 79 ms 1408 KB Output is partially correct
79 Partially correct 94 ms 1400 KB Output is partially correct
80 Partially correct 93 ms 1520 KB Output is partially correct
81 Partially correct 94 ms 1156 KB Output is partially correct
82 Partially correct 101 ms 1532 KB Output is partially correct