답안 #1038948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038948 2024-07-30T09:59:27 Z ZanP 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
10 ms 384 KB
#include "longesttrip.h"
#include <iostream>
#include <vector>
using namespace std;

void sub1(vector<int> & ans, int n){
    ans.resize(n);
    for(int i = 0;i<n;i++){ans[i] = i;}
}

void sub2(vector<int>& ans, int n) {
    ans.reserve(n);
    bool are_last_connected = are_connected({ n - 2 }, { n - 1 });
    if (!are_last_connected) { ans.push_back(n - 1); }
    ans.push_back(0);
    for (int i = 0; i < n - 1; i++) {
        if (are_connected({ i }, { i + 1 })) {
            ans.push_back(i + 1);
        }
        else {
            if (i == n - 2) { break; }
            ans.push_back(i + 2);
            ans.push_back(i + 1);
            if (!(i == n - 3 || !are_last_connected && i == n-4))ans.push_back(i + 3);
            i += 2;
        }
    }
}

vector<int> longest_trip(int n, int d){
    vector<int> ans; 
    if(d == 3){
        sub1(ans, n);
        return ans;
    }
    if(d == 2){
        sub2(ans,n);
        return ans;
    }
    return {0, 4, 5 ,2};
}

Compilation message

longesttrip.cpp: In function 'void sub2(std::vector<int>&, int)':
longesttrip.cpp:24:53: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   24 |             if (!(i == n - 3 || !are_last_connected && i == n-4))ans.push_back(i + 3);
      |                                 ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 344 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 4 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 6 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -