Submission #1057110

#TimeUsernameProblemLanguageResultExecution timeMemory
1057110MalixThousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
#include "islands.h" #include <bits/stdc++.h> #include <variant> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vii; typedef pair<int,int> pi; typedef vector<pi> pii; typedef tuple<int,int,int> tii; typedef vector<ll> li; typedef vector<li> lii; #define REP(i,a,b) for(int i=a;i<b;i++) #define F first #define S second #define PB push_back #define MP make_pair #define LSOne(s) ((s)&(-s)) ll INF=1e18+10; int inf=1e9+10; ll M=1e9+7; int n,m; vector<pii> arr; vi vis,p,ans,ind; void bfs(int x){ vis[x]=1; int s=arr[x].size(); if(s==1){ ans.PB(-1); return; } if(s==2){ int k=0; if(vis[arr[x][k].F])k++; ans.PB(arr[x][k].S); bfs(arr[x][k].F); if(ans.back()==-1)return; ans.PB(arr[x][k].S); return; } int k=0; if(vis[arr[x][k].F])k++; int z=arr[x][k].S; int y=-1; for(auto u:arr[arr[x][k].F])if(u.F==x)y=u.S; k++; while(vis[arr[x][k].F])k++; int c=arr[x][k].S; int d=-1; for(auto u:arr[arr[x][k].F])if(u.F==x&&u.S!=y)d=u.S; ans.PB(z);ans.PB(y);ans.PB(c);ans.PB(d);ans.PB(y);ans.PB(z);ans.PB(d);ans.PB(c); return; } int dfs(int x){ vis[x]=1;ind.PB(x); for(auto u:arr[x]){ if(p[x]==u.F)continue; if(vis[u.F]){ ind.PB(u.F); return u.F; } p[u.F]=x; int k=dfs(u.F); if(k!=-1)return k; } ind.pop_back(); return -1; } std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { n=N;m=M; map<pi,int> mp,mp2; REP(i,0,m){ mp[{U[i],V[i]}]=i; i++; mp2[{U[i],V[i]}]=i; } if(n==2){ if(m<=2)return false; vi a; REP(i,0,m)if(U[i]==0)a.PB(i); int p=-1; REP(i,0,m)if(U[i]!=0)p=i; int k=a.size(); if(k<2||p==-1)return false; ans.PB(a[0]);ans.PB(p);ans.PB(a[1]);ans.PB(a[0]);ans.PB(p);ans.PB(a[1]); return ans; } arr.resize(n); REP(i,0,m)arr[U[i]].PB({V[i],i}); if(U[0]==U[1]){ vis.resize(n,0); p.resize(n,-1); vis[0]=1;int k=-1; ind.PB(0); for(auto u:arr[0]){ p[u.F]=0;ind.PB(u.F); k=dfs(u.F); if(k!=-1)break; ind.pop_back(); } if(k==-1)return false; int pos=0; vi a; while(ind[pos]!=k){ a.PB(mp[{ind[pos],ind[pos+1]}]); ans.PB(mp[{ind[pos],ind[pos+1]}]); pos++; } vi tmp; int z=ind.size(); REP(i,pos,z-1)tmp.PB(ind[i]); z=tmp.size();vi b,c; REP(i,0,z-1){ b.PB(mp[{tmp[i],tmp[i+1]}]); ans.PB(mp[{tmp[i],tmp[i+1]}]); } REP(i,0,z-1){ c.PB(mp2[{tmp[i],tmp[i+1]}]); ans.PB(mp2[{tmp[i],tmp[i+1]}]); } reverse(b.begin,b.end()); reverse(c.begin,c.end()); for(auto u:b)ans.PB(u); for(auto u:c)ans.PB(u); reverse(a.begin,a.end()); for(auto u:a)ans.PB(u); return ans; } if(arr[0].size()>=2){ int x=arr[0][0].S; int y=-1; for(auto u:arr[arr[0][0].F])if(u.F==0)y=u.S; int c=arr[0][1].S; int d=-1; for(auto u:arr[arr[0][1].F])if(u.F==0)d=u.S; ans.PB(x);ans.PB(y);ans.PB(c);ans.PB(d);ans.PB(y);ans.PB(x);ans.PB(d);ans.PB(c); return ans; } if(arr[0].empty())return false; vis.resize(n,0); vis[0]=1; ans.PB(arr[0][0].S); bfs(arr[0][0].F); if(ans.back()==-1)return false; ans.PB(arr[0][0].S); return ans; }

Compilation message (stderr)

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:130:26: error: no matching function for call to 'reverse(<unresolved overloaded function type>, std::vector<int>::iterator)'
  130 |   reverse(b.begin,b.end());
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from islands.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:1165:5: note: candidate: 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
 1165 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:1165:36: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 1165 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from islands.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:249:1: note:   template argument deduction/substitution failed:
islands.cpp:130:26: note:   candidate expects 3 arguments, 2 provided
  130 |   reverse(b.begin,b.end());
      |                          ^
islands.cpp:131:26: error: no matching function for call to 'reverse(<unresolved overloaded function type>, std::vector<int>::iterator)'
  131 |   reverse(c.begin,c.end());
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from islands.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:1165:5: note: candidate: 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
 1165 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:1165:36: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 1165 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from islands.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:249:1: note:   template argument deduction/substitution failed:
islands.cpp:131:26: note:   candidate expects 3 arguments, 2 provided
  131 |   reverse(c.begin,c.end());
      |                          ^
islands.cpp:135:26: error: no matching function for call to 'reverse(<unresolved overloaded function type>, std::vector<int>::iterator)'
  135 |   reverse(a.begin,a.end());
      |                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from islands.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:1165:5: note: candidate: 'void std::reverse(_BIter, _BIter) [with _BIter = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]'
 1165 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/10/bits/stl_algo.h:1165:36: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'
 1165 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |             ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from islands.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/10/pstl/glue_algorithm_defs.h:249:1: note:   template argument deduction/substitution failed:
islands.cpp:135:26: note:   candidate expects 3 arguments, 2 provided
  135 |   reverse(a.begin,a.end());
      |                          ^