This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#define F first
#define S second
//#define endl '\n'
//#define int long long
using namespace std;
void add_element(string x);
bool check_element(string x);
void compile_set();
vt<int> restore_permutation(int n, int w, int r)
{
    { // INIT
        string s(n, '0'); s[0] = '1';
        for(int i = 0; i < n; i++, s[i] = '1') add_element(s);
        compile_set();
    }
    string cur(n, '0');
    vt<int> ans(n, n - 1);
    for(int ones = 1; ones < n; ones++)
    {
        srand(time(NULL));
        string tmp = cur;
        vt<int> used(n);
        while(true)
        {
            int i = rand() % n;
            if (tmp[i] == '1' || used[i]) continue;
            tmp[i] = '1'; used[i] = 1;
            if (check_element(tmp))
            {
                ans[i] = ones - 1;
                break;
            }
            tmp[i] = '0';
        }
        /*
        for(int i = 0; i < n; i++)
        {
            if (tmp[i] == '1') continue;
            tmp[i] = '1';
            bool exist = check_element(tmp);
            //cout << tmp << " " << exist << endl;
            if (exist)
            {
                ans[i] = ones - 1;
                break;
            }
            tmp[i] = '0';
        }
        */
        cur = tmp;
        //cout << endl;
    }
    return ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |