제출 #764684

#제출 시각아이디문제언어결과실행 시간메모리
764684raysh07Unscrambling a Messy Bug (IOI16_messy)C++17
20 / 100
1 ms468 KiB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;

int a, b;

void add(string s){
    a--;
    assert(a);
    add_element(s);
}

bool check(string s){
    b--;
    assert(b);
    return check_element(s);
}

vector<int> restore_permutation(int n, int w, int r) {
    a = w;
    b = r;
    // add_element("0");
    // compile_set();
    // check_element("0");
    // return std::vector<int>();
    
    for (int i = 0; i < n; i++){
        string s = "";
        for (int j = 0; j < n; j++){
            if (j <= i) s += "1";
            else s += "0";
        }
        
        add(s);
    }
    
    compile_set();
    vector <int> curr;
    for (int i = 0; i < n; i++) curr.push_back(i);
    
    vector <int> p(n);
    string s;
    for (int i = 0; i < n; i++) s += "0";
    int id = 0;
    
    while (curr.size()){
        random_shuffle(curr.begin(), curr.end());
        int got = -1;
        
        for (auto x : curr){
            if (x == curr.back()){
                got = x; break;
            }
            string str = s;
            str[x] = '1';
            
            if (check(str)){
                got = x;
                break;
            }
        } 
        
        assert(got != -1);
        vector <int> nc;
        for (auto x : curr){
            if (x != got) nc.push_back(x);
        }
        
        curr = nc;
        s[got] = '1';
        p[id++] = got; 
    }
    
    return p;
}
#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...