답안 #1046827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046827 2024-08-07T03:31:20 Z sonamoo 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
383 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++) {
            vector<int> tmp1;
            vector<int> tmp2;
            if (vis[i]==0) {
                tmp1.push_back(here); 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;
      |             ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 7 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 600 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 5 ms 596 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Correct 8 ms 600 KB Output is correct
7 Correct 4 ms 600 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 6 ms 856 KB Output is correct
13 Correct 4 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 5 ms 600 KB Output is correct
4 Correct 4 ms 600 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Correct 10 ms 600 KB Output is correct
7 Correct 5 ms 600 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 4 ms 600 KB Output is correct
10 Correct 4 ms 600 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 10 ms 600 KB Output is correct
15 Correct 16 ms 600 KB Output is correct
16 Correct 10 ms 600 KB Output is correct
17 Correct 8 ms 600 KB Output is correct
18 Correct 6 ms 600 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 7 ms 700 KB Output is correct
21 Correct 5 ms 600 KB Output is correct
22 Correct 5 ms 600 KB Output is correct
23 Correct 6 ms 600 KB Output is correct
24 Correct 8 ms 600 KB Output is correct
25 Correct 10 ms 600 KB Output is correct
26 Correct 11 ms 600 KB Output is correct
27 Correct 10 ms 600 KB Output is correct
28 Correct 15 ms 596 KB Output is correct
29 Correct 9 ms 600 KB Output is correct
30 Correct 10 ms 600 KB Output is correct
31 Correct 83 ms 600 KB Output is correct
32 Correct 77 ms 600 KB Output is correct
33 Correct 12 ms 692 KB Output is correct
34 Correct 23 ms 600 KB Output is correct
35 Correct 30 ms 600 KB Output is correct
36 Correct 11 ms 600 KB Output is correct
37 Correct 60 ms 600 KB Output is correct
38 Correct 211 ms 704 KB Output is correct
39 Correct 338 ms 600 KB Output is correct
40 Correct 341 ms 600 KB Output is correct
41 Correct 310 ms 848 KB Output is correct
42 Correct 377 ms 680 KB Output is correct
43 Correct 383 ms 848 KB Output is correct
44 Correct 327 ms 676 KB Output is correct
45 Correct 6 ms 600 KB Output is correct
46 Correct 8 ms 600 KB Output is correct
47 Incorrect 2 ms 600 KB Incorrect
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 600 KB Output is correct
2 Correct 6 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 5 ms 600 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 4 ms 600 KB Output is correct
10 Correct 5 ms 600 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 4 ms 600 KB Output is correct
13 Correct 5 ms 600 KB Output is correct
14 Correct 12 ms 600 KB Output is correct
15 Correct 11 ms 600 KB Output is correct
16 Incorrect 0 ms 600 KB Incorrect
17 Halted 0 ms 0 KB -