Submission #831515

#TimeUsernameProblemLanguageResultExecution timeMemory
831515MadokaMagicaFanLibrary (JOI18_library)C++14
0 / 100
35 ms308 KiB
#include "bits/stdc++.h"
#include "library.h"
using namespace std;
#define pb push_back
#define sz(v) ((int)v.size())

mt19937 rng(time(NULL));

vector<int> ans, j;

bitset<1001> in;

int query(int s, vector<int> &z) {
	shuffle(z.begin(), z.end(), rng);
	if (sz(z) == 1) return z[0];
	if (sz(z) == 0) return -1;
	int l = 0;
	int r = sz(z) - 1;
	int c1, c2;


	while (l < r) {
		int m = (l+r)/2;
		fill(j.begin(), j.end(), 0);
		for (int i = l; i <= m; ++i)
			j[z[i]-1] = 1;
		c1 = Query(j);
		j[s-1] = 1;
		c2 = Query(j);
		if (c1 >= c2)
			r = m;
		else
			l = m+1;
	}

	if (l == sz(z) -1) {
		fill(j.begin(), j.end(), 0);
		j[s-1] = 1; j[z.back()-1] = 1;
		if (Query(j) != 1)
			return -1;
	}

	return z[l];
}

void remain(vector<int> &u, int n) {
	u.clear();
	for (int i = 1; i <= n; ++i)
		if (!in[i]) u.pb(i);
}

void Solve(int n) {
	int c = 1;
	j.assign(n, 0);
	vector<int> u;

	while (c != -1) {
		in[c] = 1;
		ans.pb(c);
		remain(u, n);
		c = query(c, u);
	}

	reverse(ans.begin(), ans.end());
	c = ans.back();
	ans.pop_back();
	while (c != -1) {
		in[c] = 1;
		ans.pb(c);
		remain(u, n);
		c = query(c, u);
	}

	Answer(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...