Submission #1194250

#TimeUsernameProblemLanguageResultExecution timeMemory
1194250GabpUnscrambling a Messy Bug (IOI16_messy)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

struct Data {
  int l,r;
  vector<int> idx;

  Data(int n) {
    l = 0;
    r = n - 1;
    for (int i = 0; i < n; i++) idx.push_back(i);
  }
  
  Data(int l, int r, vector<int> idx) : l(l), r(r), idx(idx);
};

int* restore_permutation(int n, int w, int r) {
  queue<pair<int,int>> q;
  q.push({0, n - 1});
  while (!q.empty()) {
    auto [start, end] = q.front(); q.pop();
    if (start == end) continue;
    string s(n, '1');
    for (int i = start; i <= end; i++) s[i] = '0';
    int mid = start + (end - start) / 2;
    for (int i = start; i <= mid; i++) {
      string t = s;
      t[i] = '1';
      add_element(t);
    }
    
    q.push({start, mid});
    q.push({mid + 1, end});
  }
  
  compile_set();
  
  queue<Data> q2;
  q2.push(Data(n));
  int ans[n];
  
  while (!q2.empty()) {
    auto curr = q.front(); q.pop();
    int start = curr.l, end = curr.r;
    if (start == end) {
      ans[curr.idx[0]] = start;
      continue;
    }
    
    vector<int> left, right;
    string s(n, '1');
    for (auto i: curr.idx) s[i] = '0';
    for (auto i: curr.idx) {
      string t = s;
      t[i] = '1';
      if (check_element(t)) left.push_back(i);
      else right.push_back(i);
    }
    
    int mid = start + (end - start) / 2;
    q.push(Data(start, mid, left));
    q.push(Data(mid + 1, end, right));
  }
  
  return ans;
}

Compilation message (stderr)

messy.cpp: In constructor 'Data::Data(int, int, std::vector<int>)':
messy.cpp:14:61: error: expected '{' at end of input
   14 |   Data(int l, int r, vector<int> idx) : l(l), r(r), idx(idx);
      |                                                             ^
messy.cpp: In function 'int* restore_permutation(int, int, int)':
messy.cpp:29:7: error: 'add_element' was not declared in this scope
   29 |       add_element(t);
      |       ^~~~~~~~~~~
messy.cpp:36:3: error: 'compile_set' was not declared in this scope
   36 |   compile_set();
      |   ^~~~~~~~~~~
messy.cpp:44:22: error: 'struct std::pair<int, int>' has no member named 'l'
   44 |     int start = curr.l, end = curr.r;
      |                      ^
messy.cpp:45:15: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator=='
   45 |     if (start == end) {
      |         ~~~~~~^~~~~~
messy.cpp:46:16: error: 'struct std::pair<int, int>' has no member named 'idx'
   46 |       ans[curr.idx[0]] = start;
      |                ^~~
messy.cpp:52:23: error: 'struct std::pair<int, int>' has no member named 'idx'
   52 |     for (auto i: curr.idx) s[i] = '0';
      |                       ^~~
messy.cpp:53:23: error: 'struct std::pair<int, int>' has no member named 'idx'
   53 |     for (auto i: curr.idx) {
      |                       ^~~
messy.cpp:56:11: error: 'check_element' was not declared in this scope
   56 |       if (check_element(t)) left.push_back(i);
      |           ^~~~~~~~~~~~~
messy.cpp:60:28: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator-'
   60 |     int mid = start + (end - start) / 2;
      |                        ~~~~^~~~~~~
messy.cpp:61:11: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(Data)'
   61 |     q.push(Data(start, mid, left));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:86,
                 from messy.cpp:1:
/usr/include/c++/11/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  265 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:265:30: note:   no known conversion for argument 1 from 'Data' to 'const value_type&' {aka 'const std::pair<int, int>&'}
  265 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  270 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/11/bits/stl_queue.h:270:25: note:   no known conversion for argument 1 from 'Data' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  270 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
messy.cpp:62:36: error: no matching function for call to 'Data::Data(int, <unresolved overloaded function type>, std::vector<int>&)'
   62 |     q.push(Data(mid + 1, end, right));
      |                                    ^
messy.cpp:14:3: note: candidate: 'Data::Data(int, int, std::vector<int>)'
   14 |   Data(int l, int r, vector<int> idx) : l(l), r(r), idx(idx);
      |   ^~~~
messy.cpp:14:19: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to 'int'
   14 |   Data(int l, int r, vector<int> idx) : l(l), r(r), idx(idx);
      |               ~~~~^
messy.cpp:8:3: note: candidate: 'Data::Data(int)'
    8 |   Data(int n) {
      |   ^~~~
messy.cpp:8:3: note:   candidate expects 1 argument, 3 provided
messy.cpp:4:8: note: candidate: 'Data::Data(const Data&)'
    4 | struct Data {
      |        ^~~~
messy.cpp:4:8: note:   candidate expects 1 argument, 3 provided
messy.cpp:4:8: note: candidate: 'Data::Data(Data&&)'
messy.cpp:4:8: note:   candidate expects 1 argument, 3 provided
messy.cpp:65:10: warning: address of local variable 'ans' returned [-Wreturn-local-addr]
   65 |   return ans;
      |          ^~~
messy.cpp:40:7: note: declared here
   40 |   int ans[n];
      |       ^~~
messy.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
messy_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~