Submission #1082484

#TimeUsernameProblemLanguageResultExecution timeMemory
1082484BoasLongest Trip (IOI23_longesttrip)C++17
Compilation error
0 ms0 KiB
#include "longesttrip.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T1, typename T2> using indexed_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using indexed_set = indexed_map<T, null_type>; #define loop(x, i) for (int i = 0; i < (x); i++) #define loop1(x, i) for (int i = 1; i <= (x); i++) #define rev(x, i) for (int i = (int)(x) - 1; i >= 0; i--) #define itloop(x) for (auto it = begin(x); x != end(x); it++) #define itrev(x) for (auto it = rbegin(x); x != rend(x); it++) #define INF32 ((int32_t)(2e9 + 1)) #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) #define removeIn(x, l) l.erase(find(ALL(l), x)) #define pb push_back #define sz(x) (int)(x).size() #define F first #define S second #define var const auto & #define foreach(l) for (var e : l) typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef tuple<int, int, int, int> iiii; typedef vector<int> vi; typedef vector<i32> vi32; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vi32> vvi32; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vii> vvii; typedef vector<viii> vviii; typedef set<int> si; typedef set<ii> sii; typedef set<iii> siii; typedef vector<si> vsi; typedef vector<sii> vsii; typedef vector<vsi> vvsi; typedef vector<string> vstr; typedef vector<vector<string>> vvstr; typedef vector<bool> vb; typedef vector<vb> vvb; vi longest_trip(int N, int D) { if (D >= 2) { vi res(N); iota(ALL(res), 0); if (D == 3) { return res; } si resterend; loop1(N - 1, i) resterend.insert(res[i]); loop1(N - 1, i) { auto it = resterend.begin(); if (are_connected({res[i - 1]}, {*it})) { res[i] = *it; resterend.erase(it); } else { if (resterend.size() == 1) { res.insert(res.begin(), *it); res.pop_back(); return res; } res[i] = *next(it); resterend.erase(next(it)); } } return res; } else { map<ii, bool> con; auto getCon = [&](int a, int b) -> bool { if (a>b) swap(a,b); assert(a!=b); if (con.count({a, b})) return con[{a, b}]; return con[{a, b}] = are_connected({a}, {b}); } deque<int> path1, path2; path1.pb(0); for (int i = 1; i < N; i++) { if (getCon(i, path1.back())) { path1.pb(i); } else if (getCon(i, path2[0])) { path2.push_front(i); } else { for (int v:path2) path1.pb(v); path2.clear(); path2.pb(i); } } vi uq, vq, res; for (int i : path1) for (int j : path2) { uq.pb(i); vq.pb(j); } if (sz(path1) < sz(path2)) swap(path1, path2); if (are_connected(uq, vq)) { if (!getCon(path1[0], path1.back())) { if (getCon(path1[0], path2[0])) { rev(sz(path1), ix) res.pb(path1[ix]); for (int i : path2) res.pb(i); return res; } else { for (int i : path1) res.pb(i); for (int i : path2) res.pb(i); return res; } } int lo = 0, hi = sz(uq)-1; while (hi >lo) { int mid = (lo+hi)/2; vi uq2(begin(uq), begin(uq)+mid+1); vi vq2(begin(vq), begin(vq)+mid+1); if (are_connected(uq2, vq2)) { hi = mid; } else lo = mid +1; } int s1 = uq[lo], s2 = vq[lo]; loop(sz(path1), ix) { if (path1[ix] == uq[lo]) { s1 = ix; } } loop(sz(path2), ix) { if (path2[ix] == vq[lo]) { s2 = ix; } } for (int i = s1 + 1; i < sz(path1); i++) { res.pb(path1[i]); } for (int i = 0; i <= s1; i++) { res.pb(path1[i]); } for (int i = s2; i < sz(path2); i++) { res.pb(path2[i]); } for (int i = 0; i < s2; i++) { res.pb(path2[i]); } } else { if (sz(path1)>sz(path2)) { for (int v : path1) res.pb(v); } else { for (int v : path2) res.pb(v); } return res; } assert(sz(res) == N); loop(sz(res) - 1, i) assert(con[res[i]][res[i + 1]]); return res; } throw; return {}; }

Compilation message (stderr)

longesttrip.cpp: In function 'vi longest_trip(int, int)':
longesttrip.cpp:101:9: error: expected ',' or ';' before 'deque'
  101 |         deque<int> path1, path2;
      |         ^~~~~
longesttrip.cpp:102:9: error: 'path1' was not declared in this scope
  102 |         path1.pb(0);
      |         ^~~~~
longesttrip.cpp:109:32: error: 'path2' was not declared in this scope
  109 |             else if (getCon(i, path2[0]))
      |                                ^~~~~
longesttrip.cpp:122:26: error: 'path2' was not declared in this scope
  122 |             for (int j : path2)
      |                          ^~~~~
longesttrip.cpp:121:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  121 |         for (int i : path1)
      |         ^~~
longesttrip.cpp:127:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  127 |             if (sz(path1) < sz(path2)) swap(path1, path2);
      |             ^~
longesttrip.cpp:127:32: error: 'path2' was not declared in this scope
  127 |             if (sz(path1) < sz(path2)) swap(path1, path2);
      |                                ^~~~~
longesttrip.cpp:24:21: note: in definition of macro 'sz'
   24 | #define sz(x) (int)(x).size()
      |                     ^
longesttrip.cpp:132:38: error: 'path2' was not declared in this scope
  132 |                 if (getCon(path1[0], path2[0]))
      |                                      ^~~~~
longesttrip.cpp:165:21: error: 'path2' was not declared in this scope
  165 |             loop(sz(path2), ix)
      |                     ^~~~~
longesttrip.cpp:14:41: note: in definition of macro 'loop'
   14 | #define loop(x, i) for (int i = 0; i < (x); i++)
      |                                         ^
longesttrip.cpp:165:18: note: in expansion of macro 'sz'
  165 |             loop(sz(path2), ix)
      |                  ^~
longesttrip.cpp:180:37: error: 'path2' was not declared in this scope
  180 |             for (int i = s2; i < sz(path2); i++)
      |                                     ^~~~~
longesttrip.cpp:24:21: note: in definition of macro 'sz'
   24 | #define sz(x) (int)(x).size()
      |                     ^
longesttrip.cpp:186:24: error: 'path2' was not declared in this scope
  186 |                 res.pb(path2[i]);
      |                        ^~~~~
longesttrip.cpp:191:30: error: 'path2' was not declared in this scope
  191 |             if (sz(path1)>sz(path2))
      |                              ^~~~~
longesttrip.cpp:24:21: note: in definition of macro 'sz'
   24 | #define sz(x) (int)(x).size()
      |                     ^
In file included from /usr/include/c++/10/ext/pb_ds/detail/pat_trie_/pat_trie_.hpp:45,
                 from /usr/include/c++/10/ext/pb_ds/detail/container_base_dispatch.hpp:90,
                 from /usr/include/c++/10/ext/pb_ds/assoc_container.hpp:48,
                 from longesttrip.cpp:5:
longesttrip.cpp:204:40: error: no match for 'operator[]' (operand types are 'std::map<std::pair<int, int>, bool>' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
  204 |         loop(sz(res) - 1, i) assert(con[res[i]][res[i + 1]]);
      |                                        ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from longesttrip.cpp:4:
/usr/include/c++/10/bits/stl_map.h:492:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = bool; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, bool> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = bool; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  492 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:492:34: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const key_type&' {aka 'const std::pair<int, int>&'}
  492 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_map.h:512:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::pair<int, int>; _Tp = bool; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, bool> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = bool; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]'
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:512:29: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::map<std::pair<int, int>, bool>::key_type&&' {aka 'std::pair<int, int>&&'}
  512 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~