Submission #1046826

# Submission time Handle Problem Language Result Execution time Memory
1046826 2024-08-07T03:30:14 Z sonamoo Longest Trip (IOI23_longesttrip) C++17
15 / 100
8 ms 856 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++) {
            vector<int> tmp1 , tmp2;
            if (vis[i]==0) {
                tmp1.push_back(i);
                tmp2.push_back(here);
                if (!are_connected(tmp1 , tmp2)) continue;
                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]==1) {
                vector<int> tmp1; tmp1.push_back(here);
                vector<int> tmp2; tmp2.push_back(i);
                if (!are_connected(tmp1 , tmp2)) continue;
                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:46:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         if (ans.size() == N) return ans;
      |             ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB non-disjoint arrays
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 600 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 6 ms 856 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 600 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 6 ms 600 KB Output is correct
7 Correct 8 ms 600 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 6 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 7 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Incorrect 1 ms 600 KB non-disjoint arrays
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Incorrect 0 ms 600 KB non-disjoint arrays
7 Halted 0 ms 0 KB -