답안 #1061105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061105 2024-08-16T06:24:17 Z noyancanturk 가장 긴 여행 (IOI23_longesttrip) C++17
0 / 100
1 ms 596 KB
#include "longesttrip.h"

#include <bits/stdc++.h>
using namespace std;

#define pb push_back

int n,d;
deque<int>trip1,trip2;

vector<int>getslice(int l,int r,deque<int>&v){
  vector<int>res;
  for(int i=0;i<=r;i++){
    res.pb(v[i]);
  }
  return res;
}

vector<int>longest_trip(int N,int D){
  n=N,d=D;
  trip1.pb(0);
  bool side=0;
  for(int i=1;i<n;i++){
    if(!side){
      bool ok=are_connected({trip1.back()},{i});
      if(ok){
        trip1.pb(i);
      }else{
        ok=are_connected({trip1.front()},{i});
        if(ok){
          trip1.push_front(i);
        }else{
          trip2.pb(i);
        }
      }
    }
  }
  if(!are_connected(vector<int>(trip1.begin(),trip1.end()),vector<int>(trip2.begin(),trip2.end()))){
    if(trip1.size()<trip2.size())swap(trip1,trip2);
    return vector<int>(trip1.begin(),trip2.begin());
  }
  if(are_connected({trip1.front()},{trip2.front()})){
    vector<int>ans;
    for(int i=trip1.size()-1;0<=i;i--){
      ans.pb(trip1[i]);
    }
    for(int i:trip2){
      ans.pb(i);
    }
    return ans;
  }
  if(are_connected({trip1.back()},{trip2.front()})){
    vector<int>ans;
    for(int i:trip1){
      ans.pb(i);
    }
    for(int i:trip2){
      ans.pb(i);
    }
    return ans;
  }
  int ans1=-1;
  {
    int l=0,r=trip1.size()-1;
    while(l<=r){
      int mid=(l+r)>>1;
      bool ok=are_connected(getslice(l,mid,trip1),vector<int>(trip2.begin(),trip2.end()));
      if(ok){
        ans1=mid;
        r=mid-1;
      }else{
        l=mid+1;
      }
    }
  }
  assert(ans1!=-1);
  int ans2=-1;
  {
    int l=0,r=trip2.size()-1;
    while(l<=r){
      int mid=(l+r)>>1;
      bool ok=are_connected(getslice(l,mid,trip2),{trip1[ans1]});
      if(ok){
        ans1=mid;
        r=mid-1;
      }else{
        l=mid+1;
      }
    }
  }
  vector<int>ans;
  for(int i=ans1+1;i<trip1.size();i++){
    ans.pb(trip1[i]);
  }
  for(int i=0;i<=ans1;i++){
    ans.pb(trip1[i]);
  }
  ans.pb(trip2[ans2]);
  for(int i:trip2){
    if(i!=trip2[ans2])ans.pb(i);
  }
  return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for(int i=ans1+1;i<trip1.size();i++){
      |                    ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB invalid array
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 596 KB invalid array
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB invalid array
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB invalid array
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB invalid array
2 Halted 0 ms 0 KB -