제출 #1025005

#제출 시각아이디문제언어결과실행 시간메모리
1025005TonylUnscrambling a Messy Bug (IOI16_messy)C++17
49 / 100
2 ms600 KiB
#include <vector>
#include "messy.h" //"grader.cpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define REP(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define trav(x) for (auto &a : x)
#define D(x) //cerr << #x << ": " << x << endl;

int n;

vi perm; // from where?
vi to;

bool check(vector<char> vc) {
    return check_element(string(all(vc)));
}

void add(vector<char> vc) {
    add_element(string(all(vc)));
}

void prep_learn(int am) {
    vector<char> st(n, '0');
    REP(i,am) {
        st[i] = '1';
        add(st);
    }
}

void prep_power(int pw) {
    vector<char> st(n, '0');
    REP(i,4) {
        if (i == 0) st[i] = '0';
        else if (i == 1) st[i] = ((pw+1)&4) ? '1' : '0';
        else if (i == 2) st[i] = ((pw+1)&2) ? '1' : '0';
        else if (i == 3) st[i] = ((pw+1)&1) ? '1' : '0';
    }
    REP(i,n) {
        if (i < 4) continue;
        st[i] = (i&(1<<pw)) ? '1' : '0';
        if (st[i] == '1') add(st);
        st[i] = '0';
    }
}

void prep_powers() {
    REP(i, 5) prep_power(i);
}

void learn_brute(int am) {
    vector<char> st(n, '0');
    REP(i,am) {
        REP(j,n) {
            if (st[j] == '1') continue;
            st[j] = '1';
            if (check(st)) {
                to[i] = j;
                perm[j] = i;
                break;
            } else st[j] = '0';
        }
        D(to[i]);
        if (to[i] == -1) D(i);
    }
}

bool ask_pow(int pw, int tar) {
    vector<char> st(n, '0');
    REP(i,4) {
        if (i == 0) st[to[i]] = '0';
        else if (i == 1) st[to[i]] = ((pw+1)&4) ? '1' : '0';
        else if (i == 2) st[to[i]] = ((pw+1)&2) ? '1' : '0';
        else if (i == 3) st[to[i]] = ((pw+1)&1) ? '1' : '0';
    }
    assert(tar != to[0]);
    assert(tar != to[1]);
    assert(tar != to[2]);
    assert(tar != to[3]);
    st[tar] = '1';
    return check(st);
}

void learn_powers() {
    REP(i, n) {
        if (perm[i] != -1) continue;
        int ind = 0;
        REP(pw, 5) {
            if (ask_pow(pw, i)) ind += 1<<pw;
        }
        perm[i] = ind;
    }
}

std::vector<int> restore_permutation(int n_, int w, int r) {
    n = n_;
    perm = vi(n,-1); to = vi(n,-1);
    
    prep_learn(4);
    prep_powers();
    compile_set();
    learn_brute(4);
    learn_powers();

    return perm;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...