Submission #1072399

# Submission time Handle Problem Language Result Execution time Memory
1072399 2024-08-23T18:21:58 Z HorizonWest Longest Trip (IOI23_longesttrip) C++17
30 / 100
997 ms 1736 KB
#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <cstdint>
#include <cassert>
#include "longesttrip.h"
using namespace std;
vector <int> longest_trip(int n, int d)
{
    vector <vector<int>> v(n, vector <int> ()),
        s(n, vector <int> (n, -1));

    auto add = [&] (int a, int b) -> void {
        if(s[a][b] == -1){
            s[a][b] = s[b][a] = 1;
            v[a].push_back(b);
            v[b].push_back(a);
        }
    };

    if(d == 3){
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++) {
                add(i, j);
            }
        }
    }else if(d == 2){
        for(int i = 0; i < n; i++)
        {
            for(int j = i+1; j < n; j++) 
            {
                if(s[i][j] == -1){
                    s[i][j] = are_connected({ i }, { j }); 

                    if(s[i][j] == 0){
                        for(int k = 0; k < n; k++){
                            add(i, k); add(j, k);
                        }
                    }else{
                        s[i][j] = -1; add(i, j);
                    }
                }
            }
        }
    } else if(d == 1){
        for(int i = 0; i < n; i++)
        {
            for(int j = i+1; j < n; j++)
            {
                if(s[i][j] == -1){
                    s[i][j] = are_connected({ i }, { j }); 
                    if(s[i][j] == 1) {
                        s[i][j] = -1;
                        add(i, j);
                    }
                }
            }
        }
    }

    vector <int> pass(n), ans, path; 

    auto dfs = [&] (auto dfs, int node, int parent) -> void
    {
        path.push_back(node); pass[node] = 1;
        if(path.size() > ans.size()) ans = path;

        for(auto& u : v[node]) if(!pass[u])
        {
            dfs(dfs, u, node); 
        }

        path.pop_back(); 
    };

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++){ 
            pass[j] = 0;   
        }

        dfs(dfs, i, i);
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 202 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 18 ms 600 KB Output is correct
5 Correct 74 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 161 ms 452 KB Output is correct
4 Correct 441 ms 848 KB Output is correct
5 Correct 888 ms 1556 KB Output is correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 155 ms 592 KB Output is correct
4 Correct 408 ms 804 KB Output is correct
5 Correct 835 ms 1140 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 165 ms 452 KB Output is correct
9 Correct 344 ms 600 KB Output is correct
10 Correct 891 ms 1052 KB Output is correct
11 Correct 951 ms 1232 KB Output is correct
12 Correct 939 ms 1704 KB Output is correct
13 Correct 926 ms 1404 KB Output is correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 40 ms 344 KB Output is correct
17 Correct 92 ms 344 KB Output is correct
18 Correct 175 ms 600 KB Output is correct
19 Correct 327 ms 1052 KB Output is correct
20 Correct 292 ms 600 KB Output is correct
21 Correct 932 ms 1072 KB Output is correct
22 Correct 893 ms 1492 KB Output is correct
23 Correct 909 ms 1484 KB Output is correct
24 Correct 925 ms 1064 KB Output is correct
25 Correct 12 ms 344 KB Output is correct
26 Correct 7 ms 344 KB Output is correct
27 Correct 20 ms 344 KB Output is correct
28 Correct 19 ms 344 KB Output is correct
29 Correct 19 ms 408 KB Output is correct
30 Correct 208 ms 344 KB Output is correct
31 Correct 240 ms 464 KB Output is correct
32 Correct 234 ms 856 KB Output is correct
33 Correct 300 ms 548 KB Output is correct
34 Correct 311 ms 608 KB Output is correct
35 Correct 305 ms 540 KB Output is correct
36 Correct 959 ms 1196 KB Output is correct
37 Correct 880 ms 1300 KB Output is correct
38 Correct 847 ms 1124 KB Output is correct
39 Correct 766 ms 1316 KB Output is correct
40 Correct 893 ms 1292 KB Output is correct
41 Correct 873 ms 1308 KB Output is correct
42 Correct 869 ms 1204 KB Output is correct
43 Correct 895 ms 1316 KB Output is correct
44 Correct 856 ms 968 KB Output is correct
45 Correct 13 ms 344 KB Output is correct
46 Correct 9 ms 344 KB Output is correct
47 Correct 15 ms 344 KB Output is correct
48 Correct 21 ms 344 KB Output is correct
49 Correct 23 ms 344 KB Output is correct
50 Correct 213 ms 344 KB Output is correct
51 Correct 193 ms 344 KB Output is correct
52 Correct 200 ms 344 KB Output is correct
53 Correct 364 ms 600 KB Output is correct
54 Correct 300 ms 544 KB Output is correct
55 Correct 318 ms 764 KB Output is correct
56 Correct 900 ms 1288 KB Output is correct
57 Correct 878 ms 1292 KB Output is correct
58 Correct 878 ms 1068 KB Output is correct
59 Correct 878 ms 1052 KB Output is correct
60 Correct 921 ms 1056 KB Output is correct
61 Correct 860 ms 1264 KB Output is correct
62 Correct 841 ms 964 KB Output is correct
63 Correct 849 ms 1128 KB Output is correct
64 Correct 933 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Partially correct 168 ms 452 KB Output is partially correct
4 Partially correct 453 ms 1076 KB Output is partially correct
5 Partially correct 952 ms 1244 KB Output is partially correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Partially correct 154 ms 592 KB Output is partially correct
9 Partially correct 326 ms 776 KB Output is partially correct
10 Partially correct 921 ms 1152 KB Output is partially correct
11 Partially correct 891 ms 1508 KB Output is partially correct
12 Partially correct 997 ms 1312 KB Output is partially correct
13 Partially correct 872 ms 1736 KB Output is partially correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 11 ms 416 KB Output is correct
16 Incorrect 4 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -