제출 #960118

#제출 시각아이디문제언어결과실행 시간메모리
960118tutis가장 긴 여행 (IOI23_longesttrip)C++17
컴파일 에러
0 ms0 KiB
#include "longesttrip.h" mt19937_64 rng(0); std::vector<int> longest_trip(int N, int D) { vector<int>x,y; x.push_back(0); for(int i=1;i<N;i++){ if(are_connected({0}, {i})){ x.push_back(i); } else{ y.push_back(i); } } if(y.size()>0 && !are_connected(x,y)){ if(x.size()>y.size()){ return x; } else{ return y; } } if(y.empty()){ vector<int>p; for(int i=1;i<N;i++){ p.push_back(i); } shuffle(p.begin(),p.end()); vector<pair<int,int>>X; vector<int>Y; while(!p.empty()){ int x=p.back(); p.pop_back(); bool ok=false; for(auto it=p.begin();it!=p.end();it++){ if(are_connected({x}, {*it})){ X.push_back({x,*it}); p.erase(it); ok=true; break; } } if(!ok){ Y.push_back(x); } } vector<int>ans; vector<int>p; ans.push_back({1}); for(int i=2;i<N;i++){ p.push_back(i); } while(!p.empty()){ shuffle(p.begin(),p.end(),rng); bool found=false; for(int i: p){ if(are_connected({ans.back()}, {i})){ ans.push_back(i); p.erase(find(p.begin(),p.end(), i)); found=true; break; } } if(!found){ break; } } ans.push_back(0); for(int i: p){ ans.push_back(i); } return ans; } }

컴파일 시 표준 에러 (stderr) 메시지

longesttrip.cpp:3:1: error: 'mt19937_64' does not name a type
    3 | mt19937_64 rng(0);
      | ^~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:7:5: error: 'vector' was not declared in this scope
    7 |     vector<int>x,y;
      |     ^~~~~~
longesttrip.cpp:7:5: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
longesttrip.cpp:7:12: error: expected primary-expression before 'int'
    7 |     vector<int>x,y;
      |            ^~~
longesttrip.cpp:8:5: error: 'x' was not declared in this scope
    8 |     x.push_back(0);
      |     ^
longesttrip.cpp:13:13: error: 'y' was not declared in this scope
   13 |             y.push_back(i);
      |             ^
longesttrip.cpp:16:8: error: 'y' was not declared in this scope
   16 |     if(y.size()>0 && !are_connected(x,y)){
      |        ^
longesttrip.cpp:23:8: error: 'y' was not declared in this scope
   23 |     if(y.empty()){
      |        ^
longesttrip.cpp:24:16: error: expected primary-expression before 'int'
   24 |         vector<int>p;
      |                ^~~
longesttrip.cpp:26:13: error: 'p' was not declared in this scope
   26 |             p.push_back(i);
      |             ^
longesttrip.cpp:28:17: error: 'p' was not declared in this scope
   28 |         shuffle(p.begin(),p.end());
      |                 ^
longesttrip.cpp:28:9: error: 'shuffle' was not declared in this scope
   28 |         shuffle(p.begin(),p.end());
      |         ^~~~~~~
longesttrip.cpp:29:16: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   29 |         vector<pair<int,int>>X;
      |                ^~~~
      |                std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
longesttrip.cpp:29:21: error: expected primary-expression before 'int'
   29 |         vector<pair<int,int>>X;
      |                     ^~~
longesttrip.cpp:30:16: error: expected primary-expression before 'int'
   30 |         vector<int>Y;
      |                ^~~
longesttrip.cpp:36:44: error: could not convert '{<expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   36 |                 if(are_connected({x}, {*it})){
      |                                            ^
      |                                            |
      |                                            <brace-enclosed initializer list>
longesttrip.cpp:37:21: error: 'X' was not declared in this scope
   37 |                     X.push_back({x,*it});
      |                     ^
longesttrip.cpp:44:17: error: 'Y' was not declared in this scope
   44 |                 Y.push_back(x);
      |                 ^
longesttrip.cpp:47:16: error: expected primary-expression before 'int'
   47 |         vector<int>ans;
      |                ^~~
longesttrip.cpp:48:16: error: expected primary-expression before 'int'
   48 |         vector<int>p;
      |                ^~~
longesttrip.cpp:49:9: error: 'ans' was not declared in this scope
   49 |         ans.push_back({1});
      |         ^~~
longesttrip.cpp:54:39: error: 'rng' was not declared in this scope
   54 |             shuffle(p.begin(),p.end(),rng);
      |                                       ^~~
longesttrip.cpp:57:51: error: could not convert '{<expression error>}' from '<brace-enclosed initializer list>' to 'std::vector<int>'
   57 |                 if(are_connected({ans.back()}, {i})){
      |                                                   ^
      |                                                   |
      |                                                   <brace-enclosed initializer list>
longesttrip.cpp:59:29: error: 'find' was not declared in this scope
   59 |                     p.erase(find(p.begin(),p.end(), i));
      |                             ^~~~