Submission #1074461

# Submission time Handle Problem Language Result Execution time Memory
1074461 2024-08-25T10:37:19 Z YassineBenYounes Unscrambling a Messy Bug (IOI16_messy) C++17
Compilation error
0 ms 0 KB
#include "messy.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define pb push_back


int sz;
vector<string> ask;
vi res;
void preprocess(int l, int r){
    if(l == r)return;
    string s(sz, '0');
    for(int i = 0; i < l;i++){
        s[i] = '1';
    }
    for(int i = r+1; i < sz;i++){
        s[i] = '1';
    }
    int md = (l+r)/2;
    for(int i = l;i <= md;i++){
        s[i] = '1';
        ask.pb(s);
        s[i] = '0';
    }
    preprocess(l, md);
    preprocess(md+1, r);
}

string cur;

void solve(int l, int r, set<int> possible){
    if(possible.size() == 1){
        res[l] = *possible.begin();
        return;
    }
    set<int> left;
    for(int x : possible){
        cur[x] = '1';
        //cout << cur << endl;
        bool k = check_element(cur);
        
        if(k){
            left.insert(x);
        }
        cur[x] = '0';
    }
    set<int> right = possible;
    for(int x : left){
        right.erase(x);
    }
    int md = (l+r)/2;
    for(int x : right){
        cur[x] = '1';
    }
    solve(l, md, left);
    for(int x : right){
        cur[x] = '0';
    }
    for(int x : left){
        cur[x] = '1';
    }
    solve(md+1, r, right);
    for(int x : left){
        cur[x] = '0';
    }
}

std::vector<int> restore_permutation(int N, int w, int r) {
    sz = N;
    preprocess(0, sz-1);
    for(string s: ask){
        //cout << s << endl;
        add_element(s);
    }
    compile_set();
    res.resize(sz);
    //cout << endl;
    //res = {7, 6, 5, 4, 3, 2, 1, 0};
    set<int> mys;
    for(int i = 0; i < sz;i++){
        mys.insert(i);
    }
    cur.resize(sz, '0');
    solve(0, sz-1, mys);
    return res;

}

Compilation message

messy.cpp:8:1: error: 'vector' does not name a type
    8 | vector<string> ask;
      | ^~~~~~
messy.cpp:3:12: error: 'vector' does not name a type
    3 | #define vi vector<int>
      |            ^~~~~~
messy.cpp:9:1: note: in expansion of macro 'vi'
    9 | vi res;
      | ^~
messy.cpp: In function 'void preprocess(int, int)':
messy.cpp:12:5: error: 'string' was not declared in this scope
   12 |     string s(sz, '0');
      |     ^~~~~~
messy.cpp:12:5: note: suggested alternatives:
In file included from /usr/include/c++/10/string:39,
                 from messy.h:4,
                 from messy.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from messy.h:4,
                 from messy.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
messy.cpp:14:9: error: 's' was not declared in this scope
   14 |         s[i] = '1';
      |         ^
messy.cpp:17:9: error: 's' was not declared in this scope
   17 |         s[i] = '1';
      |         ^
messy.cpp:21:9: error: 's' was not declared in this scope
   21 |         s[i] = '1';
      |         ^
messy.cpp:22:9: error: 'ask' was not declared in this scope
   22 |         ask.pb(s);
      |         ^~~
messy.cpp: At global scope:
messy.cpp:29:1: error: 'string' does not name a type; did you mean 'stdin'?
   29 | string cur;
      | ^~~~~~
      | stdin
messy.cpp:31:26: error: 'set' has not been declared
   31 | void solve(int l, int r, set<int> possible){
      |                          ^~~
messy.cpp:31:29: error: expected ',' or '...' before '<' token
   31 | void solve(int l, int r, set<int> possible){
      |                             ^
messy.cpp: In function 'void solve(int, int, int)':
messy.cpp:32:8: error: 'possible' was not declared in this scope
   32 |     if(possible.size() == 1){
      |        ^~~~~~~~
messy.cpp:33:9: error: 'res' was not declared in this scope
   33 |         res[l] = *possible.begin();
      |         ^~~
messy.cpp:36:5: error: 'set' was not declared in this scope
   36 |     set<int> left;
      |     ^~~
messy.cpp:36:5: note: suggested alternatives:
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from messy.cpp:2:
/usr/include/c++/10/bits/stl_set.h:94:11: note:   'std::set'
   94 |     class set
      |           ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from messy.cpp:2:
/usr/include/c++/10/set:78:13: note:   'std::pmr::set'
   78 |       using set = std::set<_Key, _Cmp, polymorphic_allocator<_Key>>;
      |             ^~~
messy.cpp:36:9: error: expected primary-expression before 'int'
   36 |     set<int> left;
      |         ^~~
messy.cpp:37:17: error: 'possible' was not declared in this scope
   37 |     for(int x : possible){
      |                 ^~~~~~~~
messy.cpp:38:9: error: 'cur' was not declared in this scope
   38 |         cur[x] = '1';
      |         ^~~
messy.cpp:43:13: error: 'left' was not declared in this scope; did you mean 'std::left'?
   43 |             left.insert(x);
      |             ^~~~
      |             std::left
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: 'std::left' declared here
 1006 |   left(ios_base& __base)
      |   ^~~~
messy.cpp:47:9: error: expected primary-expression before 'int'
   47 |     set<int> right = possible;
      |         ^~~
messy.cpp:48:17: error: 'left' was not declared in this scope; did you mean 'std::left'?
   48 |     for(int x : left){
      |                 ^~~~
      |                 std::left
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: 'std::left' declared here
 1006 |   left(ios_base& __base)
      |   ^~~~
messy.cpp:49:9: error: 'right' was not declared in this scope; did you mean 'std::right'?
   49 |         right.erase(x);
      |         ^~~~~
      |         std::right
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: 'std::right' declared here
 1014 |   right(ios_base& __base)
      |   ^~~~~
messy.cpp:52:17: error: 'right' was not declared in this scope; did you mean 'std::right'?
   52 |     for(int x : right){
      |                 ^~~~~
      |                 std::right
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: 'std::right' declared here
 1014 |   right(ios_base& __base)
      |   ^~~~~
messy.cpp:53:9: error: 'cur' was not declared in this scope
   53 |         cur[x] = '1';
      |         ^~~
messy.cpp:55:18: error: 'left' was not declared in this scope; did you mean 'std::left'?
   55 |     solve(l, md, left);
      |                  ^~~~
      |                  std::left
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: 'std::left' declared here
 1006 |   left(ios_base& __base)
      |   ^~~~
messy.cpp:56:17: error: 'right' was not declared in this scope; did you mean 'std::right'?
   56 |     for(int x : right){
      |                 ^~~~~
      |                 std::right
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: 'std::right' declared here
 1014 |   right(ios_base& __base)
      |   ^~~~~
messy.cpp:57:9: error: 'cur' was not declared in this scope
   57 |         cur[x] = '0';
      |         ^~~
messy.cpp:60:9: error: 'cur' was not declared in this scope
   60 |         cur[x] = '1';
      |         ^~~
messy.cpp:62:20: error: 'right' was not declared in this scope; did you mean 'std::right'?
   62 |     solve(md+1, r, right);
      |                    ^~~~~
      |                    std::right
In file included 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 messy.cpp:2:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: 'std::right' declared here
 1014 |   right(ios_base& __base)
      |   ^~~~~
messy.cpp:64:9: error: 'cur' was not declared in this scope
   64 |         cur[x] = '0';
      |         ^~~
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:71:9: error: 'string' was not declared in this scope
   71 |     for(string s: ask){
      |         ^~~~~~
messy.cpp:71:9: note: suggested alternatives:
In file included from /usr/include/c++/10/string:39,
                 from messy.h:4,
                 from messy.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from messy.h:4,
                 from messy.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
messy.cpp:75:16: error: could not convert 'compile_set()' from 'void' to 'bool'
   75 |     compile_set();
      |     ~~~~~~~~~~~^~
      |                |
      |                void
messy.cpp:76:5: error: 'res' was not declared in this scope
   76 |     res.resize(sz);
      |     ^~~
messy.cpp:76:19: error: expected ')' before ';' token
   76 |     res.resize(sz);
      |                   ^
      |                   )
messy.cpp:71:8: note: to match this '('
   71 |     for(string s: ask){
      |        ^
messy.cpp:79:5: error: 'set' was not declared in this scope
   79 |     set<int> mys;
      |     ^~~
messy.cpp:79:5: note: suggested alternatives:
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from messy.cpp:2:
/usr/include/c++/10/bits/stl_set.h:94:11: note:   'std::set'
   94 |     class set
      |           ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from messy.cpp:2:
/usr/include/c++/10/set:78:13: note:   'std::pmr::set'
   78 |       using set = std::set<_Key, _Cmp, polymorphic_allocator<_Key>>;
      |             ^~~
messy.cpp:79:9: error: expected primary-expression before 'int'
   79 |     set<int> mys;
      |         ^~~
messy.cpp:81:9: error: 'mys' was not declared in this scope
   81 |         mys.insert(i);
      |         ^~~
messy.cpp:83:5: error: 'cur' was not declared in this scope
   83 |     cur.resize(sz, '0');
      |     ^~~
messy.cpp:84:20: error: 'mys' was not declared in this scope
   84 |     solve(0, sz-1, mys);
      |                    ^~~
messy.cpp:85:12: error: 'res' was not declared in this scope
   85 |     return res;
      |            ^~~