Submission #842085

# Submission time Handle Problem Language Result Execution time Memory
842085 2023-09-02T11:34:52 Z Tenis0206 Longest Trip (IOI23_longesttrip) C++17
70 / 100
75 ms 984 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;

const int nmax = 256;

int n;

int d[nmax + 5];

bool sel[nmax + 5];
int t[nmax + 5];

int split, l1, l2;

int find_next_go(int nod)
{
    vector<int> l;
    for(int i=0; i<n; i++)
    {
        if(!sel[i])
        {
            l.push_back(i);
        }
    }
    if(l.empty() || !are_connected({nod},l))
    {
        return -1;
    }
    int st = 0;
    int dr = l.size();
    while(st<dr)
    {
        int mij = (st + dr) >> 1;
        vector<int> aux;
        for(int i=st; i<=mij; i++)
        {
            aux.push_back(l[i]);
        }
        if(are_connected({nod},aux))
        {
            dr = mij;
        }
        else
        {
            st = mij + 1;
        }
    }
    return l[st];
}

void dfs(int nod)
{
    sel[nod] = true;
    int son = find_next_go(nod);
    int nr_sons = 0;
    while(son!=-1)
    {
        t[son] = nod;
        dfs(son);
        son = find_next_go(nod);
        ++nr_sons;
    }
    if(nr_sons==2)
    {
        split = nod;
    }
    if(!nr_sons)
    {
        if(l1==-1)
        {
            l1 = nod;
        }
        else
        {
            l2 = nod;
        }
    }
}

std::vector<int> solve_component(int root)
{
    split = -1, l1 = -1, l2 = -1;
    dfs(root);
    vector<int> r;
    if(l2==-1)
    {
        int nod = l1;
        r.push_back(l1);
        while(nod!=root)
        {
            nod = t[nod];
            r.push_back(nod);
        }
        return r;
    }
    vector<int> a,b;
    bool ok = are_connected({l1}, {root});
    if(!ok)
    {
        swap(l1,l2);
    }
    int nod = l1;
    while(nod!=split)
    {
        a.push_back(nod);
        nod = t[nod];
    }
    reverse(a.begin(),a.end());
    nod = l2;
    b.push_back(nod);
    while(nod!=root)
    {
        nod = t[nod];
        b.push_back(nod);
    }
    reverse(b.begin(),b.end());
    for(auto it : a)
    {
        r.push_back(it);
    }
    for(auto it : b)
    {
        r.push_back(it);
    }
    return r;
}

std::vector<int> longest_trip(int N, int D)
{
    n = N;
    for(int i=0; i<n; i++)
    {
        sel[i] = false;
        t[i] = -1;
    }
    vector<int> r;
    for(int i=0; i<n; i++)
    {
        if(sel[i])
        {
            continue;
        }
        vector<int> aux = solve_component(i);
        if(aux.size() > r.size())
        {
            r = aux;
        }
    }
    return r;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 17 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 17 ms 500 KB Output is correct
3 Correct 34 ms 600 KB Output is correct
4 Correct 44 ms 444 KB Output is correct
5 Correct 59 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 344 KB Output is correct
2 Correct 18 ms 344 KB Output is correct
3 Correct 37 ms 600 KB Output is correct
4 Correct 42 ms 444 KB Output is correct
5 Correct 61 ms 728 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 33 ms 600 KB Output is correct
9 Correct 41 ms 344 KB Output is correct
10 Correct 60 ms 956 KB Output is correct
11 Correct 53 ms 716 KB Output is correct
12 Correct 63 ms 472 KB Output is correct
13 Correct 60 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 17 ms 344 KB Output is correct
3 Correct 29 ms 344 KB Output is correct
4 Correct 47 ms 448 KB Output is correct
5 Correct 58 ms 728 KB Output is correct
6 Correct 11 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 32 ms 600 KB Output is correct
9 Correct 39 ms 440 KB Output is correct
10 Correct 58 ms 716 KB Output is correct
11 Correct 58 ms 728 KB Output is correct
12 Correct 61 ms 732 KB Output is correct
13 Correct 58 ms 720 KB Output is correct
14 Correct 13 ms 344 KB Output is correct
15 Correct 12 ms 344 KB Output is correct
16 Correct 21 ms 344 KB Output is correct
17 Correct 28 ms 344 KB Output is correct
18 Correct 31 ms 344 KB Output is correct
19 Correct 41 ms 444 KB Output is correct
20 Correct 40 ms 444 KB Output is correct
21 Correct 60 ms 712 KB Output is correct
22 Correct 56 ms 724 KB Output is correct
23 Correct 53 ms 732 KB Output is correct
24 Correct 63 ms 728 KB Output is correct
25 Correct 13 ms 344 KB Output is correct
26 Correct 12 ms 344 KB Output is correct
27 Correct 19 ms 344 KB Output is correct
28 Correct 21 ms 344 KB Output is correct
29 Correct 22 ms 344 KB Output is correct
30 Correct 39 ms 436 KB Output is correct
31 Correct 36 ms 436 KB Output is correct
32 Correct 32 ms 440 KB Output is correct
33 Correct 50 ms 600 KB Output is correct
34 Correct 38 ms 440 KB Output is correct
35 Correct 44 ms 696 KB Output is correct
36 Correct 68 ms 472 KB Output is correct
37 Correct 65 ms 732 KB Output is correct
38 Correct 60 ms 464 KB Output is correct
39 Correct 68 ms 980 KB Output is correct
40 Correct 63 ms 984 KB Output is correct
41 Correct 70 ms 708 KB Output is correct
42 Correct 60 ms 476 KB Output is correct
43 Correct 68 ms 960 KB Output is correct
44 Correct 65 ms 716 KB Output is correct
45 Correct 11 ms 344 KB Output is correct
46 Correct 12 ms 344 KB Output is correct
47 Correct 21 ms 344 KB Output is correct
48 Correct 21 ms 344 KB Output is correct
49 Correct 21 ms 344 KB Output is correct
50 Correct 34 ms 600 KB Output is correct
51 Correct 35 ms 692 KB Output is correct
52 Correct 38 ms 436 KB Output is correct
53 Correct 47 ms 444 KB Output is correct
54 Correct 40 ms 440 KB Output is correct
55 Correct 41 ms 448 KB Output is correct
56 Correct 75 ms 472 KB Output is correct
57 Correct 64 ms 972 KB Output is correct
58 Correct 58 ms 724 KB Output is correct
59 Correct 64 ms 976 KB Output is correct
60 Correct 62 ms 720 KB Output is correct
61 Correct 64 ms 704 KB Output is correct
62 Correct 54 ms 476 KB Output is correct
63 Correct 60 ms 712 KB Output is correct
64 Correct 60 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 596 KB Output is correct
2 Correct 18 ms 344 KB Output is correct
3 Correct 26 ms 344 KB Output is correct
4 Partially correct 43 ms 448 KB Output is partially correct
5 Partially correct 63 ms 728 KB Output is partially correct
6 Correct 14 ms 504 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Correct 37 ms 344 KB Output is correct
9 Partially correct 40 ms 856 KB Output is partially correct
10 Partially correct 62 ms 960 KB Output is partially correct
11 Partially correct 57 ms 480 KB Output is partially correct
12 Partially correct 52 ms 732 KB Output is partially correct
13 Partially correct 59 ms 984 KB Output is partially correct
14 Correct 10 ms 344 KB Output is correct
15 Correct 13 ms 344 KB Output is correct
16 Correct 26 ms 344 KB Output is correct
17 Correct 25 ms 344 KB Output is correct
18 Correct 33 ms 600 KB Output is correct
19 Partially correct 42 ms 440 KB Output is partially correct
20 Partially correct 46 ms 700 KB Output is partially correct
21 Correct 14 ms 344 KB Output is correct
22 Correct 8 ms 344 KB Output is correct
23 Correct 18 ms 344 KB Output is correct
24 Correct 19 ms 344 KB Output is correct
25 Correct 21 ms 340 KB Output is correct
26 Partially correct 38 ms 440 KB Output is partially correct
27 Partially correct 37 ms 440 KB Output is partially correct
28 Partially correct 40 ms 436 KB Output is partially correct
29 Partially correct 46 ms 604 KB Output is partially correct
30 Partially correct 40 ms 444 KB Output is partially correct
31 Partially correct 39 ms 500 KB Output is partially correct
32 Correct 17 ms 344 KB Output is correct
33 Correct 16 ms 344 KB Output is correct
34 Correct 23 ms 344 KB Output is correct
35 Correct 23 ms 500 KB Output is correct
36 Correct 24 ms 344 KB Output is correct
37 Partially correct 33 ms 436 KB Output is partially correct
38 Partially correct 32 ms 436 KB Output is partially correct
39 Partially correct 38 ms 444 KB Output is partially correct
40 Partially correct 45 ms 444 KB Output is partially correct
41 Partially correct 43 ms 440 KB Output is partially correct
42 Partially correct 41 ms 448 KB Output is partially correct
43 Partially correct 57 ms 704 KB Output is partially correct
44 Partially correct 51 ms 728 KB Output is partially correct
45 Partially correct 63 ms 716 KB Output is partially correct
46 Partially correct 57 ms 720 KB Output is partially correct
47 Partially correct 67 ms 720 KB Output is partially correct
48 Partially correct 67 ms 456 KB Output is partially correct
49 Partially correct 62 ms 728 KB Output is partially correct
50 Partially correct 71 ms 476 KB Output is partially correct
51 Partially correct 61 ms 472 KB Output is partially correct
52 Partially correct 66 ms 472 KB Output is partially correct
53 Partially correct 64 ms 468 KB Output is partially correct
54 Partially correct 64 ms 972 KB Output is partially correct
55 Partially correct 64 ms 716 KB Output is partially correct
56 Partially correct 56 ms 708 KB Output is partially correct
57 Partially correct 61 ms 476 KB Output is partially correct
58 Partially correct 62 ms 872 KB Output is partially correct
59 Partially correct 64 ms 724 KB Output is partially correct
60 Partially correct 68 ms 696 KB Output is partially correct
61 Partially correct 62 ms 968 KB Output is partially correct
62 Partially correct 60 ms 720 KB Output is partially correct
63 Partially correct 61 ms 704 KB Output is partially correct
64 Partially correct 57 ms 728 KB Output is partially correct
65 Partially correct 70 ms 720 KB Output is partially correct
66 Partially correct 60 ms 732 KB Output is partially correct
67 Partially correct 65 ms 480 KB Output is partially correct
68 Partially correct 63 ms 708 KB Output is partially correct
69 Partially correct 70 ms 864 KB Output is partially correct
70 Partially correct 63 ms 716 KB Output is partially correct
71 Partially correct 61 ms 960 KB Output is partially correct
72 Partially correct 59 ms 732 KB Output is partially correct
73 Partially correct 60 ms 468 KB Output is partially correct
74 Partially correct 73 ms 720 KB Output is partially correct
75 Partially correct 63 ms 472 KB Output is partially correct
76 Partially correct 54 ms 468 KB Output is partially correct
77 Partially correct 61 ms 960 KB Output is partially correct
78 Partially correct 65 ms 456 KB Output is partially correct
79 Partially correct 60 ms 724 KB Output is partially correct
80 Partially correct 67 ms 728 KB Output is partially correct
81 Partially correct 64 ms 728 KB Output is partially correct
82 Partially correct 72 ms 452 KB Output is partially correct