# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
191760 | FieryPhoenix | Unscrambling a Messy Bug (IOI16_messy) | C++11 | 0 ms | 0 KiB |
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 <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
#include "messy.h"
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007
int ans[100001];
int N;
bool contains(int x, vector<int>v){
for (int y:v)
if (y==x)
return true;
return false;
}
void ask(int l, int r){
if (l>=r)
return;
for (int i=l;i<=(l+r)/2;i++){
string s="";
for (int j=0;j<N;j++)
if (j<l || j>r)
s+='1';
else if (j==i)
s+='1';
else
s+='0';
add_element(s);
}
ask(l,(l+r)/2);
ask((l+r)/2+1,r);
}
void solve(int l, int r, vector<int>v){
string base="";
for (int i=0;i<N;i++)
base+='1';
for (int x:v)
base[x]='0';
vector<int>v2,v3;
for (int i=l;i<=r;i++){
string s=base;
s[v[i-l]]='1';
bool b=check_element(s);
if (b)
v2.push_back(v[i-l]);
}
for (int i=l;i<=r;i++)
if (!contains(v[i-l],v2))
v3.push_back(v[i-l]);
if (l+1==r){
ans[v2[0]]=l;
ans[v3[0]]=r;
return;
}
solve(l,(l+r)/2,v2);
solve((l+r)/2+1,r,v3);
}
int[] restore_permutation(int n, int w, int r){
N=n;
ask(0,n-1);
compile_set();
vector<int>v;
for (int i=0;i<n;i++)
v.push_back(i);
solve(0,n-1,v);
return ans;
}