Submission #1352616

#TimeUsernameProblemLanguageResultExecution timeMemory
1352616KALARRYUnscrambling a Messy Bug (IOI16_messy)C++20
100 / 100
1 ms580 KiB
//chockolateman

#include<bits/stdc++.h>
#include "messy.h"

using namespace std;

int N;
vector<int> ans;

void build(int start = 0,int end = N-1)
{
    if(start==end)
        return;
    string s;
    for(int i = 0 ; i < N ; i++)
        s.push_back('0');
    for(int i = 0 ; i < start ; i++)
        s[i] = '1';
    for(int i = end+1 ; i < N ; i++)
        s[i] = '1';
    int mid = (start + end)/2;
    for(int i = start ; i <= mid ; i++)
    {
        s[i] = '1';
        add_element(s);
        s[i] = '0';
    }
    build(start,mid);
    build(mid+1,end);
}

bool marked[130];

void find(int start,int end,vector<int> &ind)
{
    if(start==end)
    {
        ans[ind[0]] = start;
        return;
    }
    int mid = (start + end)/2;
    string s;
    for(int i = 0 ; i < N ; i++)
        s.push_back('1');
    for(auto x : ind)
        s[x] = '0';
    for(int i = 0 ; i < N ; i++)
        marked[i] = false;
    vector<int> new_ind;
    for(auto x : ind)
    {
        s[x] = '1';
        if(check_element(s))
        {
            marked[x] = true;
            new_ind.push_back(x);
        }
        s[x] = '0';
    }
    vector<int> other_ind;
    for(auto x : ind)
        if(!marked[x])
            other_ind.push_back(x);
    find(start,mid,new_ind);
    find(mid+1,end,other_ind);
}

std::vector<int> restore_permutation(int n, int w, int r) {
    N = n;
    build();
    compile_set();
    vector<int> ind;
    for(int i = 0 ; i < N ; i++)
        ind.push_back(i);
    for(int i = 0 ; i < N ; i++)
        ans.push_back(0);
    find(0,N-1,ind);
    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...