Submission #922006

#TimeUsernameProblemLanguageResultExecution timeMemory
922006PanndaUnscrambling a Messy Bug (IOI16_messy)C++17
70 / 100
2 ms760 KiB
#include "messy.h"
using namespace std;

vector<int> restore_permutation(int n, int w, int r) {
    int k = 32 - __builtin_clz(n);
    vector<int> p(n, 0);

    auto addSubset = [&](vector<int> subset) {
        string s(n, '0');
        for (int i : subset) {
            s[i] = '1';
        }
        add_element(s);
    };
    for (int b = 0; b < k; b++) {
        int mask = (1 << b) - 1;
        for (int base = 0; base < n; base++) {
            if (base >> b & 1) {
                vector<int> subset = { base };
                for (int aug = 0; aug < n; aug++) {
                    if ((aug & mask) != (base & mask)) {
                        subset.push_back(aug);
                    }
                }
                addSubset(subset);
            }
        }
    }

    compile_set();

    auto checkSubset = [&](vector<int> subset) {
        string s(n, '0');
        for (int i : subset) {
            s[i] = '1';
        }
        return check_element(s);
    };
    for (int b = 0; b < k; b++) {
        int mask = (1 << b) - 1;
        for (int i = 0; i < n; i++) { // here tries to infer the 2^b bit of p[i]
            vector<int> subset = { i };
            for (int j = 0; j < n; j++) {
                if ((p[j] & mask) != (p[i] & mask)) {
                    subset.push_back(j);
                }
            }
            p[i] |= checkSubset(subset) << b;
        }
    }

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