답안 #885988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885988 2023-12-11T09:47:59 Z Trisanu_Das 가장 긴 여행 (IOI23_longesttrip) C++17
컴파일 오류
0 ms 0 KB
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
 
vector<int> longest_trip(int n, int d) {
  vector<int> A, B;
  A.push_back(0);
  for(int i = 1; i < n; i++) {
    vector<int> X, Y;
    X.push_back(A.back());
    Y.push_back(i);
    if(are_connected(X, Y)) A.push_back(i);
    else B.push_back(i);
    X.clear(); Y.clear();
    if(B.size()) {
      X.push_back(A.back());
      Y.push_back(B.back());
      if(are_connected(X, Y)) 
        while(B.size()) {
        	A.pb(B.back());
        	B.pop_back();
        }
    }
  }
  if(B.size() > A.size()) swap(A, B);
  if(B.size() == 0) return A;
  vector<int> X, Y;
  X.push_back(A[0]);
  Y.push_back(B[0]);
  if(are_connected(X, Y)) {
    reverse(A.begin(), A.end());
    for(auto i : B) A.push_back(i);
    return A;
  }
  Y.clear(); Y.push_back(B.back());
  if(are_connected(X, Y)) {
    for(auto i : A) B.push_back(i);
    return B;
  }
  X.clear(); Y.clear();
  X.push_back(A.back()); Y.push_back(B[0]);
  if(are_connected(X, Y)) {
    for(auto i : B) A.push_back(i);
    return A;
  }
  if(!are_connected(A, B)) return A;
  int l = 0, r = A.size() - 1;
  while(l < r) {
    int mid = (l + r) / 2;
    vector<int> tmp;
    for(int i = 0; i < mid + 1; i++) tmp.push_back(A[i]);
    if(are_connected(tmp, B)) r = mid; else l = mid + 1;
  }
  X.clear(); X.push_back(A[l]);
  int s = 0, e = B.size()-1;
  while(s < e) {
    int mid = (s + e) / 2;
    vector<int> tmp;
    for(int i = 0; i < mid + 1; i++) tmp.push_back(B[i]);
    if(are_connected(X, tmp)) e = mid; else s = mid + 1;
  }
  vector<int> ans;
  for(int i = 0; i < A.size(); i++) ans.push_back(A[(i + l + 1) % A.size()]);
  for(int i = 0; i < B.size(); i++) ans.push_back(B[(i + s) % B.size()]);
  return ans;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:20:12: error: 'class std::vector<int>' has no member named 'pb'
   20 |          A.pb(B.back());
      |            ^~
longesttrip.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i = 0; i < A.size(); i++) ans.push_back(A[(i + l + 1) % A.size()]);
      |                  ~~^~~~~~~~~~
longesttrip.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int i = 0; i < B.size(); i++) ans.push_back(B[(i + s) % B.size()]);
      |                  ~~^~~~~~~~~~