제출 #730249

#제출 시각아이디문제언어결과실행 시간메모리
730249Nahian9696수천개의 섬 (IOI22_islands)C++17
컴파일 에러
0 ms0 KiB
#include "islands.h" #include <variant> #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define f0(i, n) for(int i = 0; i < (n); i++) #define f1(i, n) for(int i = 1; i <= (n); i++) #define ff first #define ss second #define pb push_back int opp(int n) { if(n % 2 == 0) return n+1; return n-1; } int viss[20005] = {0}; pair<bool, int> bfs(int u, int par, vi &cur, vector<pair<int, int>> grph[]) { cur.pb(u); for(auto nxt: grph[u]) { if(nxt.ff == par) continue; if(viss[nxt.ff]) { int n = cur.size(); f0(i, n) if(cur[i] == nxt.ff) return {1, i}; } viss[nxt.ff] = true; auto pp = bfs(nxt.ff, u, cur, grph); if(pp.ff) return pp; } cur.pop_back(); return {0, -1}; } std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { if(N == 2) { vi zr, on; f0(i, M) { if(U[i] == 0) zr.pb(i); else on.pb(i); } if(zr.size() < 2 || on.size() < 1) return false; return vi({zr[0], on[0], zr[1], zr[0], on[0], zr[1]}); } bool sbtsk3 = (M % 2 == 0); bool sbtsk4 = (M % 2 == 0); f0(i, M - 1) { if(i % 2 == 0) { if(U[i] != V[i+1] || V[i] != U[i+1]) { sbtsk3 = false; } if(U[i] != U[i+1] || V[i] != V[i+1]) { sbtsk4 = false; } } } if(sbtsk3) { vector<pair<int, int>> grph[N]; bool vis[N] = {0}; f0(i, M) { grph[U[i]].pb({V[i], i}); } vi ans, t_ans; int cur = 0; vis[cur] = true; if(grph[cur].size() > 1) { int x = grph[cur][0].ss, y = grph[cur][1].ss; return vi({x, opp(x), y, opp(y), opp(x), x, opp(y), y}); } else if (grph[cur].size() == 0) { return false; } else { ans.pb(grph[cur][0].ss); cur = grph[cur][0].ff; } vis[cur] = true; while(grph[cur].size() <= 2) { if(grph[cur].size() == 1) return false; for(auto nxt: grph[cur]) { if(!vis[nxt.ff]) { ans.pb(nxt.ss); cur = nxt.ff; vis[cur] = true; } } } for(auto nxt: grph[cur]) { if(!vis[nxt.ff]) { t_ans.pb(nxt.ss); } } int x = t_ans[0], y = t_ans[1]; t_ans.clear(); t_ans = vi(ans.rbegin(), ans.rend()); ans.pb(x); ans.pb(opp(x)); ans.pb(y); ans.pb(opp(y)); ans.pb(opp(x)); ans.pb(x); ans.pb(opp(y)); ans.pb(y); for(int e: t_ans) ans.pb(e); return ans; } mat[N][N]; f0(i, M) { mat[U[i]][V[i]] = i; return vi({mat[0][1], mat[1][0], mat[0][2], mat[2][0], mat[1][0], mat[0][1], mat[2][0], mat[0][2]}); } if(sbtsk4) { vector<pair<int, int>> grph[N]; // bool vis[N] = {0}; int mat[N][N]; f0(i, M) { if(i % 2 == 0) { grph[U[i]].pb({V[i], i}); mat[U[i]][V[i]] = i; } } vi cur; viss[0] = true; auto pp = bfs(0, -1, cur, grph); if(pp.ff) { vi ans, t_ans, t_t_ans; int k = pp.ss, n = cur.size(); // cout << k << endl; f0(i, k) { ans.pb(mat[cur[i]][cur[i+1]]); } t_ans = vi(ans.rbegin(), ans.rend()); for(int i = k; i < (n-1); i++) { t_t_ans.pb(mat[cur[i]][cur[i+1]]); } t_t_ans.pb(mat[cur[n-1]][cur[k]]); for(int p: t_t_ans) { ans.pb(p); } for(int p: t_t_ans) { ans.pb(opp(p)); // cout << p << " "; } // cout << endl; t_t_ans = vi(t_t_ans.rbegin(), t_t_ans.rend()); for(int p: t_t_ans) { ans.pb(p); } for(int p: t_t_ans) { ans.pb(opp(p)); } for(int p: t_ans) { ans.pb(p); } return ans; } return false; } if (N == 4) { return std::vector<int>({0, 1, 2, 4, 0, 3, 2, 1, 4, 3}); } return false; }

컴파일 시 표준 에러 (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:136:5: error: 'mat' was not declared in this scope
  136 |     mat[N][N];
      |     ^~~
islands.cpp:139:107: error: no matching function for call to 'std::vector<int>::vector(<brace-enclosed initializer list>)'
  139 |         return vi({mat[0][1], mat[1][0], mat[0][2], mat[2][0], mat[1][0], mat[0][1], mat[2][0], mat[0][2]});
      |                                                                                                           ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:653:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
  653 |  vector(_InputIterator __first, _InputIterator __last,
      |  ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:653:2: note:   template argument deduction/substitution failed:
islands.cpp:139:107: note:   candidate expects 3 arguments, 1 provided
  139 |         return vi({mat[0][1], mat[1][0], mat[0][2], mat[2][0], mat[1][0], mat[0][1], mat[2][0], mat[0][2]});
      |                                                                                                           ^
In file included from /usr/include/c++/10/vector:67,
                 from islands.h:2,
                 from islands.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:625:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  625 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:625:43: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<int>'
  625 |       vector(initializer_list<value_type> __l,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:607:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  607 |       vector(vector&& __rv, const allocator_type& __m)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:607:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_vector.h:589:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>; std::false_type = std::integral_constant<bool, false>]'
  589 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:589:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/10/bits/stl_vector.h:585:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>; std::true_type = std::integral_constant<bool, true>]'
  585 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:585:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/10/bits/stl_vector.h:575:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  575 |       vector(const vector& __x, const allocator_type& __a)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:575:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_vector.h:572:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  572 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:572:14: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>&&'
  572 |       vector(vector&&) noexcept = default;
      |              ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:553:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  553 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:553:28: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<int>&'
  553 |       vector(const vector& __x)
      |              ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:522:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  522 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:522:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/10/bits/stl_vector.h:510:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:510:24: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |              ~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:497:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  497 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:497:36: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const allocator_type&' {aka 'const std::allocator<int>&'}
  497 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |              ~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:487:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]'
  487 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:487:7: note:   candidate expects 0 arguments, 1 provided