답안 #899578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899578 2024-01-06T13:39:15 Z Szil 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
9 ms 608 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;

// bool are_connected(int[] A, int[] B);

vector<int> longest_trip(int N, int D)
{
    assert(D == 2);
    queue<int> q;
    vector<int> ans;
    for (int i = 0; i < N; i++) {
        q.push(i);
    }
    int extra = -1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        ans.emplace_back(u);
        if (q.empty()) continue;

        int v = q.front();
        if (!are_connected({u}, {v})) {
            q.pop();
            if (q.empty()) {
                extra = v;
            } else {
                q.push(v);
            }
        }
    }
    int insert = -1;
    if (extra != -1) {
        for (int i = 1; i < ans.size(); i++) {
            if (are_connected({ans[i-1]}, {extra}) && are_connected({extra}, {ans[i]})) {
                insert = i;
                break;
            }
        }
    }
    vector<int> res;
    for (int i = 0; i < ans.size(); i++) {
        if (i == insert) res.emplace_back(extra);
        res.emplace_back(ans[i]);
    }
    for (int i = 1; i < res.size(); i++) {
        assert(are_connected({res[i-1]}, {res[i]}));
    }
    return res;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 1; i < ans.size(); i++) {
      |                         ~~^~~~~~~~~~~~
longesttrip.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
longesttrip.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 1; i < res.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 600 KB Output is correct
2 Correct 9 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 8 ms 608 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -