Submission #107128

#TimeUsernameProblemLanguageResultExecution timeMemory
107128tictaccatUnscrambling a Messy Bug (IOI16_messy)C++14
20 / 100
3 ms384 KiB
#include <vector>
#include "messy.h"
#include <bits/stdc++.h>

using namespace std;

std::vector<int> restore_permutation(int n, int w, int r) {

    string guess(8,'0');
    vector<string> guesses(8);
    vector<int> p(8);
    iota(p.begin(),p.end(),0);

    string special = "00001111";

    for (int ones = 1; ones <= 7; ones++) {
        guess[ones] = '1';
        guesses[ones] = guess;
        add_element(guess);
    }

    add_element(special);

    compile_set();

    //cout << check_element("0001111") << "\n";
    bool meow = false;

    for (int i = 0; i < 256; i++) {
        string toCheck = bitset<8>(i).to_string();
       // cout << toCheck << " ";
        if (check_element(toCheck)) {
            int ones = __builtin_popcount(i);
            if (toCheck != guesses[ones] && toCheck != special) {
               // cout << toCheck << "\n";
                vector<int> swapped;
                for (int bit = 0; bit < 8; bit++) {
                    if (toCheck[bit] != guesses[ones][bit]) swapped.push_back(bit);
                }
                if (swapped.size() != 2) {
                  //  cout << toCheck << " " << swapped.size() << " " << ones << "\n";
                    // assert(ones == 4);
                    // swap(p[6],p[7]);
                    meow = true;
                }
                else {swap(p[swapped[0]],p[swapped[1]]); meow = false; break;}
            }
        }
    }

    if (meow) swap(p[6],p[7]);
    //for (int e: p) cout << e << " "; cout << "\n";

    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...