Submission #1030210

# Submission time Handle Problem Language Result Execution time Memory
1030210 2024-07-21T23:18:46 Z Agreb Longest Trip (IOI23_longesttrip) C++17
60 / 100
864 ms 852 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;

vector <int> longest_trip(int N, int D){
    vector <vector<int>> gr(N, vector<int>(N, 0));
    vector <int> path;
    for (int i = 0; i < N; i++){
        for (int j = 0; j < i; j++){
            vector <int> a{i}, b{j};
            int f = are_connected(a, b);
            gr[i][j] = gr[j][i] = f;
            if (gr[i][j]){
                path = {i, j};
            }
        }
    }
    
    if (N == 1){
        return vector<int>{0};
    }
    if (N == 2){
        if (gr[0][1]) return vector<int>{0, 1};
        else return vector <int>{0};
    }
    assert(!path.empty());
    
    vector <int> on_path(N);
    for (int u : path) on_path[u] = 1;

    while (path.size() < N){
        int P = path.size();
        int st = path[0], fin = path[P-1];

        int done = 0;
        for (int v = 0; v < N; v++){
            if (!on_path[v]){
                if (gr[st][v]){
                    reverse(path.begin(), path.end());
                    path.push_back(v);
                    on_path[v] = 1;
                    done = 1;
                    break;
                }
                if (gr[fin][v]){
                    path.push_back(v);
                    on_path[v] = 1;
                    done = 1;
                    break;
                }
            }
        }
        if (done) continue;

        assert(gr[st][fin] == 1);
        for (int v = 0; v < N; v++){
            if (!on_path[v]){
                for (int i = 0; i < P; i++){
                    if (gr[path[i]][v]){
                        vector <int> npath;
                        for (int j = 0; j < P; j++) 
                            npath.push_back(path[(j+i+1)%P]);
                        npath.push_back(v);
                        path = npath;
                        on_path[v] = 1;
                        done = 1;
                        break;
                    }
                }
                if (done) break;
            }
        }
        if (done) continue;

        if (P >= N - P) return path;
        else{
            vector <int> npath;
            for (int v = 0; v < N; v++){
                if (!on_path[v]) npath.push_back(v);
            }
            return npath;
        }
    }
    return path;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:31:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     while (path.size() < N){
      |            ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 219 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 20 ms 344 KB Output is correct
3 Correct 154 ms 344 KB Output is correct
4 Correct 419 ms 476 KB Output is correct
5 Correct 793 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 18 ms 344 KB Output is correct
3 Correct 138 ms 344 KB Output is correct
4 Correct 411 ms 476 KB Output is correct
5 Correct 809 ms 600 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Correct 147 ms 340 KB Output is correct
9 Correct 268 ms 344 KB Output is correct
10 Correct 716 ms 600 KB Output is correct
11 Correct 778 ms 600 KB Output is correct
12 Correct 841 ms 600 KB Output is correct
13 Correct 803 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 149 ms 344 KB Output is correct
4 Correct 423 ms 596 KB Output is correct
5 Correct 778 ms 600 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Correct 163 ms 344 KB Output is correct
9 Correct 299 ms 344 KB Output is correct
10 Correct 774 ms 600 KB Output is correct
11 Correct 814 ms 600 KB Output is correct
12 Correct 813 ms 600 KB Output is correct
13 Correct 818 ms 600 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 28 ms 344 KB Output is correct
17 Correct 72 ms 344 KB Output is correct
18 Correct 152 ms 344 KB Output is correct
19 Correct 310 ms 344 KB Output is correct
20 Correct 304 ms 344 KB Output is correct
21 Correct 813 ms 600 KB Output is correct
22 Correct 795 ms 600 KB Output is correct
23 Correct 792 ms 684 KB Output is correct
24 Correct 758 ms 780 KB Output is correct
25 Correct 11 ms 344 KB Output is correct
26 Correct 9 ms 344 KB Output is correct
27 Correct 25 ms 348 KB Output is correct
28 Correct 19 ms 344 KB Output is correct
29 Correct 18 ms 344 KB Output is correct
30 Correct 191 ms 344 KB Output is correct
31 Correct 185 ms 344 KB Output is correct
32 Correct 184 ms 344 KB Output is correct
33 Correct 314 ms 344 KB Output is correct
34 Correct 329 ms 344 KB Output is correct
35 Correct 271 ms 344 KB Output is correct
36 Correct 809 ms 600 KB Output is correct
37 Correct 829 ms 600 KB Output is correct
38 Correct 846 ms 600 KB Output is correct
39 Correct 805 ms 600 KB Output is correct
40 Correct 829 ms 600 KB Output is correct
41 Correct 844 ms 600 KB Output is correct
42 Correct 805 ms 596 KB Output is correct
43 Correct 840 ms 600 KB Output is correct
44 Correct 770 ms 600 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 28 ms 344 KB Output is correct
48 Correct 14 ms 344 KB Output is correct
49 Correct 19 ms 344 KB Output is correct
50 Correct 180 ms 344 KB Output is correct
51 Correct 170 ms 344 KB Output is correct
52 Correct 184 ms 344 KB Output is correct
53 Correct 258 ms 344 KB Output is correct
54 Correct 262 ms 344 KB Output is correct
55 Correct 282 ms 344 KB Output is correct
56 Correct 748 ms 680 KB Output is correct
57 Correct 753 ms 680 KB Output is correct
58 Correct 753 ms 680 KB Output is correct
59 Correct 696 ms 680 KB Output is correct
60 Correct 817 ms 688 KB Output is correct
61 Correct 830 ms 600 KB Output is correct
62 Correct 789 ms 600 KB Output is correct
63 Correct 702 ms 676 KB Output is correct
64 Correct 800 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Partially correct 157 ms 344 KB Output is partially correct
4 Partially correct 418 ms 480 KB Output is partially correct
5 Partially correct 790 ms 600 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 23 ms 344 KB Output is correct
8 Partially correct 148 ms 344 KB Output is partially correct
9 Partially correct 273 ms 344 KB Output is partially correct
10 Partially correct 818 ms 600 KB Output is partially correct
11 Partially correct 845 ms 600 KB Output is partially correct
12 Partially correct 782 ms 600 KB Output is partially correct
13 Partially correct 806 ms 600 KB Output is partially correct
14 Correct 8 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 34 ms 436 KB Output is correct
17 Partially correct 81 ms 344 KB Output is partially correct
18 Partially correct 128 ms 344 KB Output is partially correct
19 Partially correct 312 ms 344 KB Output is partially correct
20 Partially correct 302 ms 344 KB Output is partially correct
21 Correct 6 ms 344 KB Output is correct
22 Correct 9 ms 344 KB Output is correct
23 Correct 16 ms 344 KB Output is correct
24 Correct 36 ms 344 KB Output is correct
25 Correct 20 ms 344 KB Output is correct
26 Partially correct 188 ms 344 KB Output is partially correct
27 Partially correct 181 ms 344 KB Output is partially correct
28 Partially correct 189 ms 344 KB Output is partially correct
29 Partially correct 317 ms 344 KB Output is partially correct
30 Partially correct 275 ms 344 KB Output is partially correct
31 Partially correct 278 ms 344 KB Output is partially correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 8 ms 344 KB Output is correct
34 Correct 19 ms 344 KB Output is correct
35 Correct 22 ms 344 KB Output is correct
36 Correct 26 ms 344 KB Output is correct
37 Partially correct 190 ms 344 KB Output is partially correct
38 Partially correct 201 ms 344 KB Output is partially correct
39 Partially correct 181 ms 344 KB Output is partially correct
40 Partially correct 318 ms 344 KB Output is partially correct
41 Partially correct 321 ms 344 KB Output is partially correct
42 Partially correct 311 ms 344 KB Output is partially correct
43 Partially correct 827 ms 600 KB Output is partially correct
44 Partially correct 798 ms 600 KB Output is partially correct
45 Partially correct 794 ms 680 KB Output is partially correct
46 Partially correct 802 ms 852 KB Output is partially correct
47 Partially correct 793 ms 600 KB Output is partially correct
48 Partially correct 806 ms 852 KB Output is partially correct
49 Partially correct 837 ms 600 KB Output is partially correct
50 Partially correct 838 ms 600 KB Output is partially correct
51 Partially correct 792 ms 600 KB Output is partially correct
52 Partially correct 819 ms 600 KB Output is partially correct
53 Partially correct 761 ms 600 KB Output is partially correct
54 Partially correct 797 ms 600 KB Output is partially correct
55 Partially correct 781 ms 600 KB Output is partially correct
56 Partially correct 692 ms 600 KB Output is partially correct
57 Partially correct 726 ms 600 KB Output is partially correct
58 Partially correct 864 ms 600 KB Output is partially correct
59 Partially correct 716 ms 600 KB Output is partially correct
60 Partially correct 778 ms 600 KB Output is partially correct
61 Partially correct 829 ms 600 KB Output is partially correct
62 Partially correct 780 ms 852 KB Output is partially correct
63 Partially correct 698 ms 680 KB Output is partially correct
64 Partially correct 722 ms 680 KB Output is partially correct
65 Partially correct 802 ms 688 KB Output is partially correct
66 Partially correct 820 ms 676 KB Output is partially correct
67 Partially correct 802 ms 600 KB Output is partially correct
68 Partially correct 854 ms 600 KB Output is partially correct
69 Partially correct 736 ms 684 KB Output is partially correct
70 Partially correct 772 ms 600 KB Output is partially correct
71 Partially correct 778 ms 684 KB Output is partially correct
72 Partially correct 728 ms 684 KB Output is partially correct
73 Partially correct 816 ms 600 KB Output is partially correct
74 Partially correct 807 ms 600 KB Output is partially correct
75 Partially correct 739 ms 600 KB Output is partially correct
76 Partially correct 823 ms 600 KB Output is partially correct
77 Partially correct 771 ms 680 KB Output is partially correct
78 Partially correct 731 ms 676 KB Output is partially correct
79 Partially correct 701 ms 676 KB Output is partially correct
80 Partially correct 749 ms 680 KB Output is partially correct
81 Partially correct 679 ms 600 KB Output is partially correct
82 Partially correct 722 ms 600 KB Output is partially correct