Submission #1074487

# Submission time Handle Problem Language Result Execution time Memory
1074487 2024-08-25T10:46:07 Z YassineBenYounes Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
2 ms 760 KB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
#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){
    /*cout << l << " : " << r << endl;
    for(int x : possible){
        cout << x << " ";
    }
    cout << endl;*/
    if(possible.size() == 1){
        res[*possible.begin()] = l;
        return;
    }
    set<int> left;
    for(int x : possible){
        cur[x] = '1';
        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;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 8
2 Correct 1 ms 344 KB n = 8
3 Correct 0 ms 348 KB n = 8
4 Correct 0 ms 348 KB n = 8
5 Correct 1 ms 348 KB n = 8
6 Correct 1 ms 348 KB n = 8
7 Correct 0 ms 344 KB n = 8
8 Correct 0 ms 348 KB n = 8
9 Correct 0 ms 344 KB n = 8
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 1 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 0 ms 348 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 32
2 Correct 0 ms 432 KB n = 32
3 Correct 1 ms 348 KB n = 32
4 Correct 1 ms 348 KB n = 32
5 Correct 1 ms 428 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 0 ms 348 KB n = 32
8 Correct 1 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 1 ms 344 KB n = 32
11 Correct 1 ms 348 KB n = 32
12 Correct 1 ms 348 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 1 ms 348 KB n = 32
15 Correct 1 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 1 ms 344 KB n = 32
4 Correct 1 ms 348 KB n = 32
5 Correct 1 ms 344 KB n = 32
6 Correct 1 ms 344 KB n = 32
7 Correct 0 ms 348 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 344 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 0 ms 348 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 0 ms 348 KB n = 32
15 Correct 1 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 1 ms 600 KB n = 128
4 Correct 1 ms 600 KB n = 128
5 Correct 1 ms 600 KB n = 128
6 Correct 1 ms 604 KB n = 128
7 Correct 2 ms 604 KB n = 128
8 Correct 2 ms 604 KB n = 128
9 Correct 1 ms 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 1 ms 604 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 1 ms 604 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 1 ms 604 KB n = 128
4 Correct 1 ms 716 KB n = 128
5 Correct 2 ms 604 KB n = 128
6 Correct 1 ms 604 KB n = 128
7 Correct 2 ms 760 KB n = 128
8 Correct 1 ms 604 KB n = 128
9 Correct 2 ms 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 2 ms 604 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 1 ms 600 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128