제출 #401842

#제출 시각아이디문제언어결과실행 시간메모리
401842peuchUnscrambling a Messy Bug (IOI16_messy)C++17
49 / 100
2 ms332 KiB
#include "messy.h"
#include<bits/stdc++.h>
using namespace std;

std::vector<int> restore_permutation(int n, int w, int r) {
	srand(time(0));
	vector<int> x (n), y (n);
	for(int i = 0; i < n; i++)
		x[i] = i, y[i] = i;
	random_shuffle(x.begin(), x.end());
	string aux(n, '0');
	for(int i = 0; i < n; i++){
		aux[x[i]] = '1';
//		cout << "Adding: " << aux << "\n";
		add_element(aux);
	}
	compile_set();
	vector<int> marc(n, 0);
	vector<int> p(n, 0);
	aux = string(n, '0');
	int last = n - 1;
	for(int i = 0; i < n - 1; i++){
		random_shuffle(y.begin(), y.end());
		last = n - 1;
		while(marc[y[last]]) last--;
		int id = y[last];
		for(int j = 0; j < last; j++){
			if(marc[y[j]]) continue;
			aux[y[j]] = '1';
//			cout << "Checking: " << aux << "\n";
			if(!check_element(aux)) {
				aux[y[j]] = '0'; 
				continue;
			}
			id = y[j];
			break;
		}
		marc[id] = 1;
		aux[id] = '1';
		p[id] = x[i];
//		cout << aux << " " << check_element(aux) << "\n";
	}
	for(int i = 0; i < n; i++)
		if(marc[i] == 0) p[i] = x[n - 1];
    return p;
}
#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...