Submission #1046804

# Submission time Handle Problem Language Result Execution time Memory
1046804 2024-08-07T01:31:53 Z sonamoo Longest Trip (IOI23_longesttrip) C++17
15 / 100
767 ms 848 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> ans , ans2;
int vis[260];
int graph[260][260];

void init() {
    ans.clear();
    ans2.clear();
    memset(graph , 0 , sizeof(graph));
    memset(vis , 0 , sizeof(vis));
}

vector<int> longest_trip(int N, int D) {
    init();

    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            vector<int> tmp1 , tmp2; tmp1.push_back(i); tmp2.push_back(j);
            if (are_connected(tmp1 , tmp2)) graph[i][j]=graph[j][i]=1;
        }
    }

    int here = 0; vis[0]=1;
    ans.push_back(0);
    int prv=-1;
    while(prv!=here) {
        prv=here;
        for (int i = 0; i < N; i++) {
            if (vis[i]==0 && graph[here][i]==1) {
                ans.push_back(i);
                vis[i]=1;
                here=i;
                break;
            }
        }
    }
    if (D == 2) {
        if (ans.size() == N) return ans;

        reverse(ans.begin() , ans.end());
        for (int i = 0; i < N; i++) if (vis[i]==0) ans.push_back(i);
        return ans;
    }
    if (D == 3) {
        for (int i = 0; i < N; i++) ans2.push_back(i);
        return ans2;
    }

    int s=-1;
    for (int i = 0; i < N; i++) {
        if (vis[i] == 0) {
            s = i;
            break;
        }
    }
    if (s==-1) return ans;

    memset(vis , 0 , sizeof(vis));
    vis[s]=1; here=s; ans2.push_back(s);
    prv=-1;
    while(prv!=here) {
        prv=here;
        for (int i = 0; i < N; i++) {
            if (vis[i]==0 && graph[here][i]==1) {
                ans2.push_back(i);
                vis[i]=1;
                here=i;
                break;
            }
        }
    }
    if (ans2.size() < ans.size()) return ans;
    return ans2;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:42:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |         if (ans.size() == N) return ans;
      |             ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 172 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 600 KB Output is correct
2 Correct 20 ms 600 KB Output is correct
3 Correct 124 ms 600 KB Output is correct
4 Correct 351 ms 600 KB Output is correct
5 Correct 682 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 24 ms 600 KB Output is correct
3 Correct 140 ms 600 KB Output is correct
4 Correct 334 ms 600 KB Output is correct
5 Correct 722 ms 676 KB Output is correct
6 Correct 5 ms 600 KB Output is correct
7 Correct 17 ms 600 KB Output is correct
8 Correct 123 ms 600 KB Output is correct
9 Correct 267 ms 600 KB Output is correct
10 Correct 684 ms 600 KB Output is correct
11 Correct 725 ms 684 KB Output is correct
12 Correct 716 ms 676 KB Output is correct
13 Correct 688 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 19 ms 600 KB Output is correct
3 Correct 112 ms 600 KB Output is correct
4 Correct 340 ms 600 KB Output is correct
5 Correct 646 ms 680 KB Output is correct
6 Correct 6 ms 600 KB Output is correct
7 Correct 25 ms 600 KB Output is correct
8 Correct 135 ms 600 KB Output is correct
9 Correct 248 ms 600 KB Output is correct
10 Correct 700 ms 688 KB Output is correct
11 Correct 714 ms 676 KB Output is correct
12 Correct 660 ms 676 KB Output is correct
13 Correct 693 ms 680 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 10 ms 600 KB Output is correct
16 Correct 26 ms 600 KB Output is correct
17 Correct 77 ms 600 KB Output is correct
18 Correct 120 ms 600 KB Output is correct
19 Correct 298 ms 600 KB Output is correct
20 Correct 273 ms 600 KB Output is correct
21 Correct 708 ms 848 KB Output is correct
22 Correct 767 ms 680 KB Output is correct
23 Correct 693 ms 680 KB Output is correct
24 Correct 723 ms 848 KB Output is correct
25 Correct 10 ms 600 KB Output is correct
26 Correct 8 ms 600 KB Output is correct
27 Correct 13 ms 600 KB Output is correct
28 Correct 15 ms 600 KB Output is correct
29 Correct 18 ms 600 KB Output is correct
30 Correct 164 ms 600 KB Output is correct
31 Correct 154 ms 600 KB Output is correct
32 Correct 175 ms 600 KB Output is correct
33 Correct 259 ms 676 KB Output is correct
34 Correct 247 ms 600 KB Output is correct
35 Correct 264 ms 600 KB Output is correct
36 Correct 684 ms 680 KB Output is correct
37 Correct 705 ms 676 KB Output is correct
38 Correct 691 ms 680 KB Output is correct
39 Correct 723 ms 676 KB Output is correct
40 Correct 668 ms 684 KB Output is correct
41 Correct 734 ms 680 KB Output is correct
42 Correct 693 ms 684 KB Output is correct
43 Correct 722 ms 676 KB Output is correct
44 Correct 710 ms 680 KB Output is correct
45 Correct 12 ms 600 KB Output is correct
46 Correct 8 ms 600 KB Output is correct
47 Incorrect 4 ms 600 KB Incorrect
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 18 ms 600 KB Output is correct
3 Partially correct 118 ms 600 KB Output is partially correct
4 Partially correct 331 ms 600 KB Output is partially correct
5 Partially correct 674 ms 676 KB Output is partially correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 18 ms 600 KB Output is correct
8 Partially correct 103 ms 600 KB Output is partially correct
9 Partially correct 231 ms 600 KB Output is partially correct
10 Partially correct 672 ms 680 KB Output is partially correct
11 Partially correct 705 ms 676 KB Output is partially correct
12 Partially correct 750 ms 676 KB Output is partially correct
13 Partially correct 748 ms 600 KB Output is partially correct
14 Correct 12 ms 600 KB Output is correct
15 Correct 10 ms 600 KB Output is correct
16 Incorrect 1 ms 600 KB Incorrect
17 Halted 0 ms 0 KB -