답안 #846618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846618 2023-09-08T07:30:00 Z ttamx 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
7 ms 600 KB
#include "longesttrip.h"
#include<bits/stdc++.h>

using namespace std;

vector<int> longest_trip(int N, int D)
{
    if(D==3){
        vector<int> ans(N);
        iota(ans.begin(),ans.end(),0);
        return ans;
    }
    if(D==2){
        deque<int> path;
        for(int i=0;i<3;i++)path.emplace_back(i);
        for(int i=1;i<3;i++){
            if(!are_connected({i-1},{i})){
                swap(path[0],path[i-1]);
                swap(path[2],path[i]);
                break;
            }
        }
        for(int i=3;i<N;i++){
            if(are_connected({i},{path[0]})){
                path.emplace_front(i);
            }else{
                path.emplace_back(i);
            }
        }
        vector<int> ans;
        for(auto x:path)ans.emplace_back(x);
        return ans;
    }
    vector<int> path[2];
    for(int i=0;i<2;i++)path[i].emplace_back(i);
    for(int i=3;i<N;i++){
        if(are_connected({i},{path[0].back()})){
            path[0].emplace_back(i);
            continue;
        }
        if(are_connected({i},{path[1].back()})){
            path[1].emplace_back(i);
            continue;
        }
        while(!path[1].empty()){
            path[0].emplace_back(path[1].back());
            path[1].pop_back();
        }
        path[1].emplace_back(i);
    }
    if(path[0].size()<path[1].size())swap(path[0],path[1]);
    return path[0];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 7 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 4 ms 344 KB Output is correct
11 Correct 5 ms 600 KB Output is correct
12 Correct 5 ms 600 KB Output is correct
13 Correct 6 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 -