Submission #789365

#TimeUsernameProblemLanguageResultExecution timeMemory
789365fatemetmhrUnscrambling a Messy Bug (IOI16_messy)C++17
38 / 100
1 ms340 KiB
//  ~ Be Name Khoda ~  //



#include "messy.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")

using namespace std;

typedef long long ll;

#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second

const int maxn  =  1e6   + 10;
const int maxn5 =  5e5   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   + 7;
const ll  inf   =  1e18;

string t = "";

bool mark[maxn5];

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

    for(int i = 0; i < n; i++)
        t.pb('0');

    vector <int> ans, rev;
    for(int i = 0; i < n; i++){
        ans.pb(i);
        rev.pb(i);
        string s = t;
        for(int j = 0; j <= i; j++)
            s[j] = '1';
        add_element(s);
    }
    compile_set();
    for(int i = 0; i < n; i++){
        string s = t;
        for(int j = 0; j <= i; j++)
            s[rev[j]] = '1';
        if(ans[i] == i)
            s[i] = '0';
        for(int j = 0; j < n; j++) if(!mark[j]){
            s[j] = '1';
            //cout << "to check " << i << ' ' << j << ' ' << s << endl;
            if(check_element(s)){
                mark[j] = true;
                ans[j] = i;
                rev[i] = j;
                break;
            }
            s[j] = '0';
        }
    }
    return ans;

    /*
    build(0, n);
    compile_set();
    sort(all(av));
    vector <int> ans;
    for(int i = 0; i < n; i++)
        ans.pb(i);
    while(av.size()){
        string s = av.back().se;
        int l = av.back().fi.se.fi, r = av.back().fi.se.se;
        int mid = (l + r) >> 1;
        av.pop_back();
        if(check_element(s))
            continue;
        for(int i = l; i < mid; i++) for(int j = mid; j < r; j++){
            s[i] = '0';
            s[j] = '1';
            if(check_element(s)){
                swap(ans[i], ans[j]);
                return ans;
            }
            s[i] = '1';
            s[j] = '0';
        }
    }
    return ans;
    */
}
#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...