Submission #887453

#TimeUsernameProblemLanguageResultExecution timeMemory
887453djs100201Longest Trip (IOI23_longesttrip)C++17
Compilation error
0 ms0 KiB
#include "longesttrip.h" #include<random> #include<bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define all(v) v.begin(),v.end() using namespace std; using ll = long long; using P = pair<ll, ll>; using PP = pair<ll, P>; const ll n_ = 1e5 + 505, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353; ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k; mt19937_64 seed(20010223); vector<int> longest_trip(int N,int D){ vector<int>ret; n=N; if(D==3){ for(int i=0;i<n;i++)ret.push_back(i); } else if(D==2){ vector<int>A={0},B={1},C={2}; deque<ll>T; if(are_connected(A,B)){ T.push_back(0); T.push_back(1); for(int i=2;i<n;i++){ A.clear(),B.clear(),C.clear(); A.push_back(T.front()); C.push_back(i); if(are_connected(A,C))T.push_front(i); else T.push_back(i); } } else if(are_connected(B,C)){ T.push_back(1); T.push_back(2); for(int i=0;i<n;i++){ if(i==1 || i==2)continue; A.clear(),B.clear(),C.clear(); A.push_back(T.front()); C.push_back(i); if(are_connected(A,C))T.push_front(i); else T.push_back(i); } } else if(are_connected(A,C)){ T.push_back(0); T.push_back(2); for(int i=0;i<n;i++){ if(i==0 || i==2)continue; A.clear(),B.clear(),C.clear(); A.push_back(T.front()); C.push_back(i); if(are_connected(A,C))T.push_front(i); else T.push_back(i); } } while(T.size())ret.push_back(T.back()),T.pop_back(); } else{ vector<vector<ll>>S; vector<int>id(n); for(int i=0;i<n;i++)id[i]=i; uniform_real_distribution<int>R(0,n-1); random_device rd; mt19937 gen(rd()); for(int i=0;i<100000;i++){ a=R(gen()); b=R(gen()); swap(id[a],id[b]); } S.push_back({0}); for(int i=1;i<n;i++){ a=S.back().back(); if(are_connected({a},{i}))S.back().push_back(i); else{ if(S.size()>=2 && S.back().size()==1)S[S.size()-2].push_back(i); else S.push_back({i}); } } if(S.size()==1){ for(auto nxt:S[0])ret.push_back(nxt); } else { vector<ll>A,B; A=S[0],B=S[1]; for(int i=2;i<n;i++){ vector<ll>T=S[i]; if(are_connected({A.back()},{T[0]})){ for(auto nxt:T)A.push_back(nxt); } else if(are_connected({B.back()},{T[0]})){ for(auto nxt:T)B.push_back(nxt); } else{ reverse(all(B)); for(auto nxt:B)A.push_back(nxt); B=T; } } if(A.size()<B.size())swap(A,B); return A; } } return ret; }

Compilation message (stderr)

In file included from /usr/include/c++/10/random:49,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/random.h: In instantiation of 'class std::uniform_real_distribution<int>':
longesttrip.cpp:65:34:   required from here
/usr/include/c++/10/bits/random.h:1733:56: error: static assertion failed: result_type must be a floating point type
 1733 |       static_assert(std::is_floating_point<_RealType>::value,
      |                                                        ^~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:69:13: error: no match for call to '(std::uniform_real_distribution<int>) (std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type)'
   69 |    a=R(gen());
      |             ^
In file included from /usr/include/c++/10/random:49,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/random.h:1849:2: note: candidate: 'std::uniform_real_distribution<_RealType>::result_type std::uniform_real_distribution<_RealType>::operator()(_UniformRandomNumberGenerator&) [with _UniformRandomNumberGenerator = long unsigned int; _RealType = int; std::uniform_real_distribution<_RealType>::result_type = int]' (near match)
 1849 |  operator()(_UniformRandomNumberGenerator& __urng)
      |  ^~~~~~~~
/usr/include/c++/10/bits/random.h:1849:2: note:   conversion of argument 1 would be ill-formed:
longesttrip.cpp:69:11: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to an rvalue of type 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'}
   69 |    a=R(gen());
      |        ~~~^~
In file included from /usr/include/c++/10/random:49,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/random.h:1854:2: note: candidate: 'template<class _UniformRandomNumberGenerator> std::uniform_real_distribution<_RealType>::result_type std::uniform_real_distribution<_RealType>::operator()(_UniformRandomNumberGenerator&, const std::uniform_real_distribution<_RealType>::param_type&) [with _UniformRandomNumberGenerator = _UniformRandomNumberGenerator; _RealType = int]'
 1854 |  operator()(_UniformRandomNumberGenerator& __urng,
      |  ^~~~~~~~
/usr/include/c++/10/bits/random.h:1854:2: note:   template argument deduction/substitution failed:
longesttrip.cpp:69:13: note:   candidate expects 2 arguments, 1 provided
   69 |    a=R(gen());
      |             ^
longesttrip.cpp:70:13: error: no match for call to '(std::uniform_real_distribution<int>) (std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type)'
   70 |    b=R(gen());
      |             ^
In file included from /usr/include/c++/10/random:49,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/random.h:1849:2: note: candidate: 'std::uniform_real_distribution<_RealType>::result_type std::uniform_real_distribution<_RealType>::operator()(_UniformRandomNumberGenerator&) [with _UniformRandomNumberGenerator = long unsigned int; _RealType = int; std::uniform_real_distribution<_RealType>::result_type = int]' (near match)
 1849 |  operator()(_UniformRandomNumberGenerator& __urng)
      |  ^~~~~~~~
/usr/include/c++/10/bits/random.h:1849:2: note:   conversion of argument 1 would be ill-formed:
longesttrip.cpp:70:11: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to an rvalue of type 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'}
   70 |    b=R(gen());
      |        ~~~^~
In file included from /usr/include/c++/10/random:49,
                 from longesttrip.cpp:2:
/usr/include/c++/10/bits/random.h:1854:2: note: candidate: 'template<class _UniformRandomNumberGenerator> std::uniform_real_distribution<_RealType>::result_type std::uniform_real_distribution<_RealType>::operator()(_UniformRandomNumberGenerator&, const std::uniform_real_distribution<_RealType>::param_type&) [with _UniformRandomNumberGenerator = _UniformRandomNumberGenerator; _RealType = int]'
 1854 |  operator()(_UniformRandomNumberGenerator& __urng,
      |  ^~~~~~~~
/usr/include/c++/10/bits/random.h:1854:2: note:   template argument deduction/substitution failed:
longesttrip.cpp:70:13: note:   candidate expects 2 arguments, 1 provided
   70 |    b=R(gen());
      |             ^
longesttrip.cpp:76:22: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   76 |    if(are_connected({a},{i}))S.back().push_back(i);
      |                      ^
longesttrip.cpp:76:22: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:90:29: warning: narrowing conversion of 'A.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   90 |     if(are_connected({A.back()},{T[0]})){
      |                       ~~~~~~^~
longesttrip.cpp:90:29: warning: narrowing conversion of 'A.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:90:39: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   90 |     if(are_connected({A.back()},{T[0]})){
      |                                       ^
longesttrip.cpp:90:39: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:93:34: warning: narrowing conversion of 'B.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   93 |     else if(are_connected({B.back()},{T[0]})){
      |                            ~~~~~~^~
longesttrip.cpp:93:34: warning: narrowing conversion of 'B.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:93:44: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   93 |     else if(are_connected({B.back()},{T[0]})){
      |                                            ^
longesttrip.cpp:93:44: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:103:11: error: could not convert 'A' from 'vector<long long int>' to 'vector<int>'
  103 |    return A;
      |           ^
      |           |
      |           vector<long long int>