제출 #138886

#제출 시각아이디문제언어결과실행 시간메모리
138886arthurconmyUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
5 ms508 KiB
#include <bits/stdc++.h>
#include "messy.h"
 
using namespace std;
 
vector<int> restore_permutation(int n, int w, int r) 
{
	for(int no_groups=2; no_groups<=n; no_groups*=2)
	{
		for(int g=0; g<no_groups; g+=2)
		{
			for(int i=0; i<int(n/no_groups); i++)
			{
				string S = "";
 
				for(int d=1; d <= g*int(n/no_groups); d++) S+='1';
				for(int d=1; d <= i; d++) S+='0';
 
				S+='1';
 
				for(int d=1; d < int(n/no_groups) - i; d++) S+='0';
				for(int d=1; d <= int(n/no_groups); d++) S+='0';
 
				while(int(S.size())<n) S+='1';
 
				add_element(S);
			}
		}
	}
 
	compile_set();
 
	vector<vector<int>> group(4*n); // kinda like a segment tree (indexing) I guess
 
	for(int i=0; i<n; i++) group[1].push_back(i); // initially we know fuck all about everything
 
	for(int no_groups=1; no_groups<n; no_groups*=2) // this is the number of groups we have at this stage
	{
		for(int g=0; g<no_groups; g++)
		{
			string S="";
 
			for(int i=0; i<n; i++) S+='0';
 
			for(int i=no_groups; i<no_groups*2; i++)
			{
				if(i != no_groups+g)
				{
					for(auto u:group[i]) S[u]='1';
				}
			}
 
			for(auto u:group[no_groups+g])
			{
				string S2 = S;
				S2[u]='1';
 
				if(check_element(S2))
				{
					group[2*(no_groups+g)].push_back(u);
				}
 
				else
				{
					group[2*(no_groups+g) + 1].push_back(u);
				}
			}
		}
	}
 
	vector<int> ans(n);
 
	for(int i=n; i<n+n; i++)
	{
		ans[group[i][0]]=i-n;
	}
 
	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...