Submission #1018755

# Submission time Handle Problem Language Result Execution time Memory
1018755 2024-07-10T09:25:40 Z ProtonDecay314 Mechanical Doll (IOI18_doll) C++17
Compilation error
0 ms 0 KB
// AM+DG

/*

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
#define L(i, varmn, varmx) for(ll i = varmn; i < varmx; i++)
#define LR(i, varmx, varmn) for(ll i = varmx; i > varmn; i--)
#define LI(i, varmn, varmx) for(int i = varmn; i < varmx; i++)
#define LIR(i, varmx, varmn) for(int i = varmx; i > varmn; i--)
#define pb push_back
#include "doll.h"

struct pot_switch {
    int id;
    int x;
    int y;
}

void construct_switches(int base_switch_num, const vi& to_connect, int p2, int offset, vector<pot_switch>& switches_to_construct) {
    int size = to_connect.size();

    if(size == 2) {
        // Handle the special case here
        switches_to_construct.pb({base_switch_num - offset, to_connect[p2 + offset - ((p2 << 1) - 1)], to_connect[(p2 << 1) + offset - ((p2 << 1) - 1)]});
    } else if(size == 3) {
        // Handle the special case here
        switches_to_construct.pb({base_switch_num - offset, base_switch_num - (offset + p2), to_connect[(p2 << 1) + offset - ((p2 << 1) - 1)]});

        // Recurse towards the first child
        construct_switches(base_switch_num, to_connect, p2 << 1, offset + p2, switches_to_construct);
    } else {
        // Recursive case
        switches_to_construct.pb({base_switch_num - offset, base_switch_num - (offset + p2), base_switch_num - (offset + (p2 << 1))});

        // Recurse left
        construct_switches(base_switch_num, to_connect, p2 << 1, offset + p2, switches_to_construct);

        // Recurse right
        construct_switches(base_switch_num, to_connect, p2 << 1, offset + (p2 << 1), switches_to_construct);
    }
}

void create_circuit(int m, std::vector<int> a) {
    int n = a.size();
    vi c(m + 1);
    c[0] = -1;
    for (int i = 1; i <= m; ++i) {
        c[i] = 1;
    }
    // vi x(N), y(N);
    // for (int k = 0; k < N; ++k) {
    //     x[k] = y[k] = a[k];
    // }

    vi x;
    vi y;

    vvi adjmat;

    LI(i, 0, m + 1) {
        vi adjmatr;
        adjmat.pb(adjmatr);
    }

    LI(i, -1, n) {
        if(i == -1) {
            adjmat[0].pb(a[i + 1]);
        } else if(i == n - 1) {
            adjmat[a[i]].pb(0);
        } else {
            adjmat[a[i]].pb(a[i + 1]);
        }
    }

    int last_switch = 0;
    LI(i, 0, m + 1) {
        int cur_num_next = adjmat[i].size();
        if(cur_num_next == 1) {
            c[i] = adjmat[i][0];
        } else {
            /*
            Construct switches needs...
            whatever the last switch was,
            the list of things it should connect the leaf node to
            the current power of two separation (starts at 1 and doubles)
            the current offset (starts at 0)
            for the left tree, it increments by power * 1
            for the right, its power * 2
            Left tree must be of size ceil(N / 2)
            right is size floor(N / 2)

            */

            vector<pot_switch> switches_to_construct;
            construct_switches(last_switch - 1, adjmat[i], 1, 0, switches_to_construct);
            sort(switches_to_construct.begin(), switches_to_construct.end(), greater<int>()); // Sort by decreasing ID
            LI(i, 0, cur_num_next - 1) {
                x.pb(switches_to_construct[i].x);
                y.pb(switches_to_construct[i].y);
            }
            last_switch -= cur_num_next - 1;
        }
    }

    answer(c, x, y);

    return;
}

Compilation message

doll.cpp:28:2: error: expected ';' after struct definition
   28 | }
      |  ^
      |  ;
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from doll.cpp:6:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Iterator2 = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = std::greater<int>]':
/usr/include/c++/10/bits/stl_algo.h:82:17:   required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1924:34:   required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1958:38:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = std::greater<int>]'
doll.cpp:107:92:   required from here
/usr/include/c++/10/bits/predefined_ops.h:156:30: error: no match for call to '(std::greater<int>) (pot_switch&, pot_switch&)'
  156 |         { return bool(_M_comp(*__it1, *__it2)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from doll.cpp:6:
/usr/include/c++/10/bits/stl_function.h:375:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = int]'
  375 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_function.h:375:29: note:   no known conversion for argument 1 from 'pot_switch' to 'const int&'
  375 |       operator()(const _Tp& __x, const _Tp& __y) const
      |                  ~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from doll.cpp:6:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = pot_switch; _Iterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = std::greater<int>]':
/usr/include/c++/10/bits/stl_algo.h:1826:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Val_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1854:36:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1886:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1977:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = std::greater<int>]'
doll.cpp:107:92:   required from here
/usr/include/c++/10/bits/predefined_ops.h:238:23: error: no match for call to '(std::greater<int>) (pot_switch&, pot_switch&)'
  238 |  { return bool(_M_comp(__val, *__it)); }
      |                ~~~~~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from doll.cpp:6:
/usr/include/c++/10/bits/stl_function.h:375:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = int]'
  375 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_function.h:375:29: note:   no known conversion for argument 1 from 'pot_switch' to 'const int&'
  375 |       operator()(const _Tp& __x, const _Tp& __y) const
      |                  ~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from doll.cpp:6:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Value = pot_switch; _Compare = std::greater<int>]':
/usr/include/c++/10/bits/stl_heap.h:139:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Distance = long int; _Tp = pot_switch; _Compare = __gnu_cxx::__ops::_Iter_comp_val<std::greater<int> >]'
/usr/include/c++/10/bits/stl_heap.h:246:23:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Distance = long int; _Tp = pot_switch; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_heap.h:355:22:   required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1666:23:   required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1937:25:   required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1953:27:   required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:1974:25:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<std::greater<int> >]'
/usr/include/c++/10/bits/stl_algo.h:4892:18:   required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<pot_switch*, std::vector<pot_switch> >; _Compare = std::greater<int>]'
doll.cpp:107:92:   required from here
/usr/include/c++/10/bits/predefined_ops.h:194:23: error: no match for call to '(std::greater<int>) (pot_switch&, pot_switch&)'
  194 |  { return bool(_M_comp(*__it, __val)); }
      |                ~~~~~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from doll.cpp:6:
/usr/include/c++/10/bits/stl_function.h:375:7: note: candidate: 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = int]'
  375 |       operator()(const _Tp& __x, const _Tp& __y) const
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_function.h:375:29: note:   no known conversion for argument 1 from 'pot_switch' to 'const int&'
  375 |       operator()(const _Tp& __x, const _Tp& __y) const
      |                  ~~~~~~~~~~~^~~