답안 #853589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853589 2023-09-24T17:10:45 Z Andrey 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
758 ms 856 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;

bool haha[1000][1000];

vector<int> longest_trip(int n, int d)
{
    for(int i = 0; i < n; i++) {
        haha[i][i] = false;
        for(int j = i+1; j < n; j++) {
            bool c = are_connected({i},{j});
            haha[i][j] = c;
            haha[j][i] = c;
        }
    }
    vector<bool> bruh(n,true);
    deque<int> ans;
    ans.push_back(0);
    bruh[0] = false;
    for(int i = 1; i < n; i++) {
        if(haha[0][i]) {
            ans.push_back(i);
            bruh[i] = false;
            break;
        }
    }
    if(ans.size() > 1) {
        for(int i = 2; i < n; i++) {
            int p;
            for(int j = 0; j < n; j++) {
                if(bruh[j]) {
                    p = j;
                }
            }
            int a = ans[0],b = ans[ans.size()-1];
            if(haha[a][p]) {
                ans.push_front(p);
                bruh[p] = false;
            }
            else if(haha[b][p]) {
                ans.push_back(p);
                bruh[p] = false;
            }
            else {
                int c = -1;
                for(int j = 0; j < n; j++) {
                    for(int y = 0; y < n; y++) {
                        if(bruh[j] == false && bruh[y] == true && haha[j][y]) {
                            c = y;
                        }
                    }
                }
                if(c == -1) {
                    break;
                }
                ans.push_back(c);
                bruh[c] = false;
            }
        }
    }

    vector<int> wut(0);
    for(int i = 0; i < ans.size(); i++) {
        wut.push_back(ans[i]);
    }
    if(ans.size() == n) {
        return wut;
    }
    else {
        if(ans.size() < n-ans.size()) {
            wut.clear();
            for(int i = 0; i < n; i++) {
                if(bruh[i]) {
                    wut.push_back(i);
                }
            }
        }
    }
    return wut;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
longesttrip.cpp:67:19: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   67 |     if(ans.size() == n) {
      |        ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 180 ms 672 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 129 ms 344 KB Output is correct
4 Correct 331 ms 544 KB Output is correct
5 Correct 670 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 22 ms 596 KB Output is correct
3 Correct 124 ms 344 KB Output is correct
4 Correct 348 ms 540 KB Output is correct
5 Correct 737 ms 856 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 18 ms 344 KB Output is correct
8 Correct 123 ms 344 KB Output is correct
9 Correct 299 ms 588 KB Output is correct
10 Correct 758 ms 856 KB Output is correct
11 Correct 723 ms 672 KB Output is correct
12 Correct 661 ms 664 KB Output is correct
13 Correct 736 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 21 ms 344 KB Output is correct
3 Correct 123 ms 600 KB Output is correct
4 Correct 329 ms 344 KB Output is correct
5 Correct 734 ms 672 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 131 ms 344 KB Output is correct
9 Correct 285 ms 528 KB Output is correct
10 Correct 684 ms 664 KB Output is correct
11 Correct 726 ms 664 KB Output is correct
12 Correct 687 ms 856 KB Output is correct
13 Correct 748 ms 856 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 13 ms 344 KB Output is correct
16 Incorrect 2 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Partially correct 123 ms 344 KB Output is partially correct
4 Partially correct 356 ms 544 KB Output is partially correct
5 Partially correct 728 ms 668 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 28 ms 344 KB Output is correct
8 Partially correct 115 ms 344 KB Output is partially correct
9 Partially correct 288 ms 592 KB Output is partially correct
10 Partially correct 747 ms 668 KB Output is partially correct
11 Partially correct 644 ms 688 KB Output is partially correct
12 Partially correct 750 ms 856 KB Output is partially correct
13 Partially correct 752 ms 672 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Incorrect 2 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -