Submission #764695

#TimeUsernameProblemLanguageResultExecution timeMemory
764695raysh07Unscrambling a Messy Bug (IOI16_messy)C++17
49 / 100
1 ms340 KiB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
 
vector<int> restore_permutation(int n, int w, int 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_element(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;
    srand(69);
    
    while (curr.size()){
        random_shuffle(curr.begin(), curr.end());
        int got = -1;
        
        for (auto x : curr){
            
            string str = s;
            str[x] = '1';
            
            if (check_element(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; 
    }
    
    vector <int> inv(n);
    for (int i = 0; i < n; i++) inv[p[i]] = i;
    
    return inv;
}
#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...