답안 #894703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894703 2023-12-28T18:14:01 Z JeanBombeur 가장 긴 여행 (IOI23_longesttrip) C++17
60 / 100
839 ms 2208 KB
#include "longesttrip.h"
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

//  <|°_°|>

const int MAX_NODES = 256;

bool Edge[MAX_NODES][MAX_NODES];
vector <int> Adj[MAX_NODES];

vector <int> Path;

int Seen[MAX_NODES];

int Dfs(int node) {
    if (Seen[node])
        return 0;
    Path.push_back(node);
    int ans = Seen[node] = 1;
    for (int dest : Adj[node])
        ans += Dfs(dest);
    return ans;
}

vector <int> longest_trip(int nbNodes, int density) {
    
    for (int i = 0; i < nbNodes; i ++)
    {
        Adj[i].clear();
        fill_n(Edge[i], nbNodes, 0);
    }
    Path.clear();
    fill_n(Seen, nbNodes, 0);
    for (int i = 0; i < nbNodes; i ++)
    {
        for (int j = i + 1; j < nbNodes; j ++)
        {
            if (are_connected({i}, {j}))
            {
                Edge[i][j] = Edge[j][i] = 1;
                Adj[i].push_back(j);
                Adj[j].push_back(i);
            }
        }
    }
    int n = Dfs(0);
    if (n != nbNodes)
    {
        int first = (2 * n) >= nbNodes;
        vector <int> v;
        for (int i = 0; i < nbNodes; i ++)
        {
            if (Seen[i] == first)
                v.push_back(i);
        }
        return v;
    }
    vector <int> v = {0};
    for (int a : Path)
    {
        if (!a)
            continue;
        if (Edge[v.back()][a])
            v.push_back(a);
        else if (Edge[v[0]][a])
        {
            reverse(v.begin(), v.end());
            v.push_back(a);
        }
        else
        {
            vector <int> nv;
            while (!Edge[a][v.back()])
            {
                nv.push_back(v.back());
                v.pop_back();
            }
            v.push_back(a);
            reverse(v.begin(), v.end());
            for (int a : nv)
                v.push_back(a);
        }
    }
    return v;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 169 ms 1248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 123 ms 708 KB Output is correct
4 Correct 358 ms 1140 KB Output is correct
5 Correct 735 ms 1424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 30 ms 344 KB Output is correct
3 Correct 128 ms 712 KB Output is correct
4 Correct 386 ms 1392 KB Output is correct
5 Correct 773 ms 1532 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 118 ms 608 KB Output is correct
9 Correct 254 ms 848 KB Output is correct
10 Correct 675 ms 1564 KB Output is correct
11 Correct 805 ms 1188 KB Output is correct
12 Correct 722 ms 1368 KB Output is correct
13 Correct 728 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 18 ms 340 KB Output is correct
3 Correct 122 ms 856 KB Output is correct
4 Correct 341 ms 996 KB Output is correct
5 Correct 706 ms 1440 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 19 ms 344 KB Output is correct
8 Correct 107 ms 704 KB Output is correct
9 Correct 264 ms 1124 KB Output is correct
10 Correct 728 ms 1832 KB Output is correct
11 Correct 648 ms 1804 KB Output is correct
12 Correct 723 ms 1428 KB Output is correct
13 Correct 723 ms 1364 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 9 ms 596 KB Output is correct
16 Correct 48 ms 344 KB Output is correct
17 Correct 69 ms 856 KB Output is correct
18 Correct 126 ms 968 KB Output is correct
19 Correct 278 ms 976 KB Output is correct
20 Correct 260 ms 980 KB Output is correct
21 Correct 753 ms 1428 KB Output is correct
22 Correct 747 ms 1792 KB Output is correct
23 Correct 742 ms 1452 KB Output is correct
24 Correct 748 ms 1728 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 25 ms 344 KB Output is correct
28 Correct 23 ms 344 KB Output is correct
29 Correct 23 ms 344 KB Output is correct
30 Correct 165 ms 868 KB Output is correct
31 Correct 163 ms 856 KB Output is correct
32 Correct 196 ms 856 KB Output is correct
33 Correct 290 ms 972 KB Output is correct
34 Correct 264 ms 864 KB Output is correct
35 Correct 285 ms 1112 KB Output is correct
36 Correct 745 ms 1432 KB Output is correct
37 Correct 730 ms 1372 KB Output is correct
38 Correct 752 ms 1360 KB Output is correct
39 Correct 750 ms 1740 KB Output is correct
40 Correct 675 ms 1656 KB Output is correct
41 Correct 730 ms 1104 KB Output is correct
42 Correct 703 ms 1340 KB Output is correct
43 Correct 714 ms 1828 KB Output is correct
44 Correct 709 ms 1636 KB Output is correct
45 Correct 7 ms 344 KB Output is correct
46 Correct 7 ms 344 KB Output is correct
47 Correct 24 ms 344 KB Output is correct
48 Correct 17 ms 344 KB Output is correct
49 Correct 21 ms 344 KB Output is correct
50 Correct 163 ms 856 KB Output is correct
51 Correct 160 ms 1228 KB Output is correct
52 Correct 161 ms 600 KB Output is correct
53 Correct 293 ms 712 KB Output is correct
54 Correct 255 ms 764 KB Output is correct
55 Correct 255 ms 600 KB Output is correct
56 Correct 709 ms 1624 KB Output is correct
57 Correct 759 ms 1220 KB Output is correct
58 Correct 742 ms 1380 KB Output is correct
59 Correct 738 ms 1368 KB Output is correct
60 Correct 751 ms 1676 KB Output is correct
61 Correct 812 ms 1284 KB Output is correct
62 Correct 760 ms 1292 KB Output is correct
63 Correct 766 ms 1732 KB Output is correct
64 Correct 788 ms 1540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 17 ms 344 KB Output is correct
3 Partially correct 113 ms 1112 KB Output is partially correct
4 Partially correct 329 ms 1632 KB Output is partially correct
5 Partially correct 794 ms 1192 KB Output is partially correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Partially correct 116 ms 708 KB Output is partially correct
9 Partially correct 261 ms 1112 KB Output is partially correct
10 Partially correct 685 ms 1816 KB Output is partially correct
11 Partially correct 745 ms 1408 KB Output is partially correct
12 Partially correct 833 ms 1152 KB Output is partially correct
13 Partially correct 800 ms 1124 KB Output is partially correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 41 ms 340 KB Output is correct
17 Partially correct 80 ms 600 KB Output is partially correct
18 Partially correct 148 ms 852 KB Output is partially correct
19 Partially correct 228 ms 856 KB Output is partially correct
20 Partially correct 277 ms 984 KB Output is partially correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 10 ms 344 KB Output is correct
23 Correct 23 ms 344 KB Output is correct
24 Correct 31 ms 344 KB Output is correct
25 Correct 24 ms 344 KB Output is correct
26 Partially correct 159 ms 856 KB Output is partially correct
27 Partially correct 172 ms 616 KB Output is partially correct
28 Partially correct 170 ms 600 KB Output is partially correct
29 Partially correct 290 ms 1112 KB Output is partially correct
30 Partially correct 231 ms 848 KB Output is partially correct
31 Partially correct 274 ms 496 KB Output is partially correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 11 ms 344 KB Output is correct
34 Correct 21 ms 344 KB Output is correct
35 Correct 24 ms 344 KB Output is correct
36 Correct 25 ms 344 KB Output is correct
37 Partially correct 166 ms 968 KB Output is partially correct
38 Partially correct 168 ms 720 KB Output is partially correct
39 Partially correct 167 ms 1108 KB Output is partially correct
40 Partially correct 270 ms 1120 KB Output is partially correct
41 Partially correct 284 ms 748 KB Output is partially correct
42 Partially correct 261 ms 1136 KB Output is partially correct
43 Partially correct 742 ms 1684 KB Output is partially correct
44 Partially correct 743 ms 1980 KB Output is partially correct
45 Partially correct 747 ms 2208 KB Output is partially correct
46 Partially correct 722 ms 1952 KB Output is partially correct
47 Partially correct 729 ms 1112 KB Output is partially correct
48 Partially correct 709 ms 1348 KB Output is partially correct
49 Partially correct 759 ms 1412 KB Output is partially correct
50 Partially correct 718 ms 1676 KB Output is partially correct
51 Partially correct 735 ms 1644 KB Output is partially correct
52 Partially correct 839 ms 1188 KB Output is partially correct
53 Partially correct 744 ms 1352 KB Output is partially correct
54 Partially correct 768 ms 1416 KB Output is partially correct
55 Partially correct 728 ms 1492 KB Output is partially correct
56 Partially correct 721 ms 1520 KB Output is partially correct
57 Partially correct 724 ms 1912 KB Output is partially correct
58 Partially correct 718 ms 1476 KB Output is partially correct
59 Partially correct 711 ms 1596 KB Output is partially correct
60 Partially correct 711 ms 1112 KB Output is partially correct
61 Partially correct 703 ms 1504 KB Output is partially correct
62 Partially correct 764 ms 1128 KB Output is partially correct
63 Partially correct 826 ms 1184 KB Output is partially correct
64 Partially correct 728 ms 1844 KB Output is partially correct
65 Partially correct 722 ms 1424 KB Output is partially correct
66 Partially correct 718 ms 1624 KB Output is partially correct
67 Partially correct 718 ms 1360 KB Output is partially correct
68 Partially correct 765 ms 1520 KB Output is partially correct
69 Partially correct 705 ms 1424 KB Output is partially correct
70 Partially correct 722 ms 1520 KB Output is partially correct
71 Partially correct 750 ms 1680 KB Output is partially correct
72 Partially correct 812 ms 1700 KB Output is partially correct
73 Partially correct 732 ms 1664 KB Output is partially correct
74 Partially correct 702 ms 1908 KB Output is partially correct
75 Partially correct 733 ms 1572 KB Output is partially correct
76 Partially correct 736 ms 1372 KB Output is partially correct
77 Partially correct 701 ms 1360 KB Output is partially correct
78 Partially correct 747 ms 1712 KB Output is partially correct
79 Partially correct 696 ms 1420 KB Output is partially correct
80 Partially correct 708 ms 1316 KB Output is partially correct
81 Partially correct 695 ms 1116 KB Output is partially correct
82 Partially correct 708 ms 1608 KB Output is partially correct