Submission #887911

# Submission time Handle Problem Language Result Execution time Memory
887911 2023-12-15T13:10:39 Z djs100201 Longest Trip (IOI23_longesttrip) C++17
Compilation error
0 ms 0 KB
#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;
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;
		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<int>A,B;
			A=S[0],B=S[1];
			for(int i=2;i<S.size();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);
			if(are_connected(A,B)){
				if(are_connected({A[0]},{B[0]})){
					reverse(all(A));
					for(auto nxt:A)ret.push_back(nxt);
					for(auto nxt:B)ret.push_back(nxt);
				}
				else if(are_connected({A[0]},{B.back()})){
					for(auto nxt:B)ret.push_back(nxt);
					for(auto nxt:A)ret.push_back(nxt);
				}
				else if(are_connected({A.back()},{B[0]})){
					for(auto nxt:A)ret.push_back(nxt);
					for(auto nxt:B)ret.push_back(nxt);
				}
				else if(are_connected({A.back()},{B.back()})){
					reverse(all(B));
					for(auto nxt:A)ret.push_back(nxt);
					for(auto nxt:B)ret.push_back(nxt);
				}
				else{
					ll l=0,r=A.size()-1,aa=A.size(),bb=B.size();
					while(l<=r){
						ll mid=(l+r)/2;
						vector<ll>T;
						for(int i=0;i<=mid;i++)T.push_back(A[i]);
						if(are_connected(T,B)){
							aa=min(aa,mid);
							r=mid-1;
						}
						else l=mid+1;
					}
					l=0,r=B.size()-1;
					while(l<=r){
						ll mid=(l+r)/2;
						vector<ll>T;
						for(int i=0;i<=mid;i++)T.push_back(B[i]);
						if(are_connected({aa},T)){
							bb=min(bb,mid);
							r=mid-1;
						}
						else l=mid+1;
					}
					for(int i=aa+1;i<A.size();i++)ret.push_back(A[i]);
					for(int i=0;i<=aa;i++)ret.push_back(A[i]);
					for(int i=bb;i<B.size();i++)ret.push_back(B[i]);
					for(int i=0;i<bb;i++)ret.push_back(B[i]);
				}
			}
			else{
				for(auto i:A)ret.push_back(i);
			}
		}
	}
	return ret;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:64:22: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   64 |    if(are_connected({a},{i}))S.back().push_back(i);
      |                      ^
longesttrip.cpp:64:22: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:75:9: error: no match for 'operator=' (operand types are 'std::vector<int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'})
   75 |    A=S[0],B=S[1];
      |         ^
In file included from /usr/include/c++/10/vector:72,
                 from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
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:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
longesttrip.cpp:75:16: error: no match for 'operator=' (operand types are 'std::vector<int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'})
   75 |    A=S[0],B=S[1];
      |                ^
In file included from /usr/include/c++/10/vector:72,
                 from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
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:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
longesttrip.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |    for(int i=2;i<S.size();i++){
      |                ~^~~~~~~~~
longesttrip.cpp:78: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]
   78 |     if(are_connected({A.back()},{T[0]})){
      |                                       ^
longesttrip.cpp:78: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:81: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]
   81 |     else if(are_connected({B.back()},{T[0]})){
      |                                            ^
longesttrip.cpp:81: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:87:8: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'std::vector<long long int>')
   87 |      B=T;
      |        ^
In file included from /usr/include/c++/10/vector:72,
                 from longesttrip.h:1,
                 from longesttrip.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'const std::vector<int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
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:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::vector<int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<long long int>' to 'std::initializer_list<int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
longesttrip.cpp:116:24: error: could not convert 'T' from 'vector<long long int>' to 'vector<int>'
  116 |       if(are_connected(T,B)){
      |                        ^
      |                        |
      |                        vector<long long int>
longesttrip.cpp:127:25: warning: narrowing conversion of 'aa' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
  127 |       if(are_connected({aa},T)){
      |                         ^~
longesttrip.cpp:127:25: warning: narrowing conversion of 'aa' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:127:29: error: could not convert 'T' from 'vector<long long int>' to 'vector<int>'
  127 |       if(are_connected({aa},T)){
      |                             ^
      |                             |
      |                             vector<long long int>
longesttrip.cpp:133:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |      for(int i=aa+1;i<A.size();i++)ret.push_back(A[i]);
      |                     ~^~~~~~~~~
longesttrip.cpp:135:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |      for(int i=bb;i<B.size();i++)ret.push_back(B[i]);
      |                   ~^~~~~~~~~