답안 #841179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841179 2023-09-01T10:29:43 Z NicolaAbusaad2014 가장 긴 여행 (IOI23_longesttrip) C++17
15 / 100
89 ms 336 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

void split(vector<int>&v,int sz,vector<int>&a,vector<int>&b)
{
    for(int i=0;i<sz;i++){
        a.push_back(v[i]);
    }
    for(int i=sz;i<v.size();i++){
        b.push_back(v[i]);
    }
}

void BS(vector<int>A,vector<int>B,int&s,int&e)
{
    while(A.size()>1){
        vector<int>a,b;
        split(A,(A.size())/2,a,b);
        if(are_connected(a,B)){
            swap(A,a);
        }
        else{
            swap(A,b);
        }
    }
    while(B.size()>1){
        vector<int>a,b;
        split(B,(B.size())/2,a,b);
        if(are_connected(A,a)){
            swap(B,a);
        }
        else{
            swap(B,b);
        }
    }
    s=A[0];
    e=B[0];
}

std::vector<int> longest_trip(int N, int D)
{
    vector<int>path(1);
    vector<bool>vis(N);
    vis[0]=true;
    while(path.size()<N){
        int a=path.front();
        int b=path.back();
        int c,d;
        vector<int>rest;
        for(int i=0;i<N;i++){
            if(!vis[i]){
                rest.push_back(i);
            }
        }
        if(are_connected(vector<int>(1,a),rest)){
            BS(vector<int>(1,a),rest,c,d);
            path.insert(path.begin(),d);
            vis[d]=true;
            continue;
        }
        if(are_connected(vector<int>(1,b),rest)){
            BS(vector<int>(1,b),rest,c,d);
            path.push_back(d);
            vis[d]=true;
            continue;
        }
        if(!are_connected(path,rest)){
            if(path.size()>=rest.size()){
                return path;
            }
            return rest;
        }
        BS(path,rest,c,d);
        for(int i=0;i<path.size();i++){
            if(path[i]==c){
                c=i;
                break;
            }
        }
        for(int i=0;i<rest.size();i++){
            if(rest[i]==d){
                d=i;
                break;
            }
        }
        vector<int>ans;
        for(int i=c+1;i<path.size();i++){
            ans.push_back(path[i]);
        }
        for(int i=0;i<=c;i++){
            ans.push_back(path[i]);
        }
        for(int i=d;i<rest.size();i++){
            ans.push_back(path[i]);
        }
        for(int i=0;i<d;i++){
            ans.push_back(path[i]);
        }
        return ans;
    }
    return path;
}

Compilation message

longesttrip.cpp: In function 'void split(std::vector<int>&, int, std::vector<int>&, std::vector<int>&)':
longesttrip.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=sz;i<v.size();i++){
      |                  ~^~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:47:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |     while(path.size()<N){
      |           ~~~~~~~~~~~^~
longesttrip.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int i=0;i<path.size();i++){
      |                     ~^~~~~~~~~~~~
longesttrip.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int i=0;i<rest.size();i++){
      |                     ~^~~~~~~~~~~~
longesttrip.cpp:89:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(int i=c+1;i<path.size();i++){
      |                       ~^~~~~~~~~~~~
longesttrip.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for(int i=d;i<rest.size();i++){
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 19 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 18 ms 208 KB Output is correct
3 Correct 21 ms 304 KB Output is correct
4 Correct 65 ms 300 KB Output is correct
5 Correct 70 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 16 ms 208 KB Output is correct
3 Correct 33 ms 336 KB Output is correct
4 Correct 65 ms 304 KB Output is correct
5 Correct 77 ms 320 KB Output is correct
6 Correct 11 ms 208 KB Output is correct
7 Correct 27 ms 208 KB Output is correct
8 Correct 41 ms 208 KB Output is correct
9 Correct 46 ms 208 KB Output is correct
10 Correct 85 ms 308 KB Output is correct
11 Correct 75 ms 304 KB Output is correct
12 Correct 89 ms 324 KB Output is correct
13 Correct 60 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 208 KB Output is correct
2 Correct 19 ms 208 KB Output is correct
3 Correct 48 ms 300 KB Output is correct
4 Correct 67 ms 208 KB Output is correct
5 Correct 83 ms 208 KB Output is correct
6 Correct 14 ms 208 KB Output is correct
7 Correct 23 ms 208 KB Output is correct
8 Correct 42 ms 208 KB Output is correct
9 Correct 57 ms 304 KB Output is correct
10 Correct 73 ms 208 KB Output is correct
11 Correct 80 ms 336 KB Output is correct
12 Correct 76 ms 336 KB Output is correct
13 Correct 66 ms 324 KB Output is correct
14 Correct 16 ms 208 KB Output is correct
15 Correct 17 ms 208 KB Output is correct
16 Incorrect 1 ms 208 KB Incorrect
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 208 KB Output is correct
2 Correct 24 ms 208 KB Output is correct
3 Correct 41 ms 300 KB Output is correct
4 Partially correct 64 ms 312 KB Output is partially correct
5 Partially correct 70 ms 316 KB Output is partially correct
6 Correct 14 ms 208 KB Output is correct
7 Correct 25 ms 208 KB Output is correct
8 Correct 41 ms 208 KB Output is correct
9 Partially correct 47 ms 208 KB Output is partially correct
10 Partially correct 71 ms 312 KB Output is partially correct
11 Partially correct 88 ms 336 KB Output is partially correct
12 Partially correct 66 ms 324 KB Output is partially correct
13 Partially correct 84 ms 320 KB Output is partially correct
14 Correct 16 ms 208 KB Output is correct
15 Correct 14 ms 208 KB Output is correct
16 Incorrect 1 ms 208 KB Incorrect
17 Halted 0 ms 0 KB -