답안 #135487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135487 2019-07-24T06:40:07 Z Mahdi_Jfri Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
4 ms 508 KB
#include "messy.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

const int maxn = 2e2 + 20;

int res[maxn];

void solve1(int n , int l , int r)
{
	int m = (r - l);

	string x = string(l , '1') , y = string(n - r , '1');
	if(m == 2)
	{
		add_element(x + "10" + y);
		return;
	}

	m = (l + r) / 2;
	for(int i = l; i < m; i++)
	{
		string tmp = x + string(r - l , '0') + y;
		tmp[i] = '1';
		add_element(tmp);
	}

	solve1(n , l , m);
	solve1(n , m , r);
}

bool check(string tmp , int k)
{
	tmp[k] = '1';
	bool f = check_element(tmp);
	return f;
}

void solve2(int n , int l , int r , vector<int> candid)
{
	string tmp = string(n , '1');
	for(auto x : candid)
		tmp[x] = '0';

	assert((int)candid.size() == r - l);

	if(r - l == 2)
	{
		if(!check(tmp , candid[0]))
			swap(candid[0] , candid[1]);
		res[l] = candid[0];
		res[l + 1] = candid[1];
		return;
	}

	vector<int> x , y;
	for(int i = 0; i < r - l; i++)
	{
		if(check(tmp , candid[i]))
			x.pb(candid[i]);
		else
			y.pb(candid[i]);
	}

	int m = (l + r) / 2;
	solve2(n , l , m , x);
	solve2(n , m , r , y);
}

vector<int> restore_permutation(int n, int w, int r)
{
	solve1(n , 0 , n);
	compile_set();

	vector<int> candid;
	for(int i = 0; i < n; i++)
		candid.pb(i);
	solve2(n , 0 , n , candid);

	for(int i = 0; i < n; i++)
		candid[res[i]] = i;
	return candid;
}








# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 8
2 Correct 2 ms 256 KB n = 8
3 Correct 2 ms 256 KB n = 8
4 Correct 2 ms 376 KB n = 8
5 Correct 2 ms 376 KB n = 8
6 Correct 3 ms 256 KB n = 8
7 Correct 2 ms 376 KB n = 8
8 Correct 2 ms 256 KB n = 8
9 Correct 2 ms 376 KB n = 8
10 Correct 2 ms 376 KB n = 8
11 Correct 2 ms 376 KB n = 8
12 Correct 2 ms 376 KB n = 8
13 Correct 2 ms 376 KB n = 8
14 Correct 2 ms 376 KB n = 8
15 Correct 2 ms 376 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 32
2 Correct 2 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 2 ms 376 KB n = 32
5 Correct 2 ms 376 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 2 ms 376 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 2 ms 376 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 2 ms 376 KB n = 32
13 Correct 2 ms 380 KB n = 32
14 Correct 2 ms 376 KB n = 32
15 Correct 2 ms 376 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 32
2 Correct 2 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 2 ms 376 KB n = 32
5 Correct 3 ms 376 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 2 ms 376 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 2 ms 376 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 2 ms 376 KB n = 32
13 Correct 2 ms 380 KB n = 32
14 Correct 2 ms 376 KB n = 32
15 Correct 2 ms 252 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 508 KB n = 128
4 Correct 4 ms 504 KB n = 128
5 Correct 4 ms 504 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 504 KB n = 128
8 Correct 4 ms 504 KB n = 128
9 Correct 4 ms 504 KB n = 128
10 Correct 4 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 3 ms 488 KB n = 128
13 Correct 4 ms 504 KB n = 128
14 Correct 4 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 504 KB n = 128
4 Correct 3 ms 504 KB n = 128
5 Correct 4 ms 504 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 504 KB n = 128
8 Correct 4 ms 504 KB n = 128
9 Correct 4 ms 504 KB n = 128
10 Correct 4 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 4 ms 504 KB n = 128
13 Correct 4 ms 504 KB n = 128
14 Correct 4 ms 508 KB n = 128
15 Correct 4 ms 504 KB n = 128