답안 #1115557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115557 2024-11-20T15:56:40 Z Gray 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
39 ms 608 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ff first
#define ss second
#define ln "\n"
ll n, d;
pair<ll, vector<ll>> mx;

vector<int> longest_trip(int N, int D)
{
    n=N; d=D;
    vector<int> a = {0}, b;
    for (int i=1; i<N; i++){
        if (are_connected({a.back()}, vector<int>{i})){
            a.push_back(i);
        }else{
            b.push_back(i);
        }
    }
    if (a.empty() or b.empty()){
        return a.empty()?b:a;
    }else if (are_connected(a, b)){
        ll l=0, r=a.size();
        while (l<r){
            vector<int> test;
            ll mid = (l+r)/2;
            for (ll i=l; i<=mid; i++){
                test.push_back(a[i]);
            }
            if (are_connected(test, b)){
                r=mid;
            }else l=mid+1;
        }
        int conA = a[r];
        l=0; r=b.size();
        while (l<r){
            vector<int> test;
            ll mid = (l+r)/2;
            for (ll i=l; i<=mid; i++){
                test.push_back(b[i]);
            }
            if (are_connected(test, {conA})){
                r=mid;
            }else l=mid+1;
        }
        int conB = b[r];

        vector<int> res;
        for (auto ch:a){
            if (ch==conA) continue;
            res.push_back(ch);
        }
        res.push_back(conA);
        res.push_back(conB);
        for (auto ch:b){
            if (ch==conB) continue;
            res.push_back(ch);
        }
        return res;
    }else{
        if (a.size()>b.size()) return a;
        else return b;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 5 ms 336 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 336 KB Output is correct
2 Correct 16 ms 336 KB Output is correct
3 Correct 16 ms 336 KB Output is correct
4 Correct 16 ms 336 KB Output is correct
5 Correct 15 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 504 KB Output is correct
2 Correct 14 ms 508 KB Output is correct
3 Correct 15 ms 336 KB Output is correct
4 Correct 17 ms 336 KB Output is correct
5 Correct 17 ms 336 KB Output is correct
6 Correct 31 ms 336 KB Output is correct
7 Incorrect 1 ms 336 KB Incorrect
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 336 KB Output is correct
2 Correct 14 ms 336 KB Output is correct
3 Correct 13 ms 336 KB Output is correct
4 Correct 14 ms 336 KB Output is correct
5 Correct 19 ms 336 KB Output is correct
6 Correct 39 ms 336 KB Output is correct
7 Incorrect 1 ms 336 KB Incorrect
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 336 KB Output is correct
2 Correct 18 ms 336 KB Output is correct
3 Correct 18 ms 336 KB Output is correct
4 Correct 19 ms 336 KB Output is correct
5 Correct 16 ms 608 KB Output is correct
6 Correct 24 ms 336 KB Output is correct
7 Incorrect 1 ms 336 KB Incorrect
8 Halted 0 ms 0 KB -