제출 #267207

#제출 시각아이디문제언어결과실행 시간메모리
267207ShisukoLibrary (JOI18_library)C++14
0 / 100
143 ms384 KiB
#include <cstdio>
#include <chrono>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include "library.h"
using namespace std;

void Solve(int N)
{
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	vector<int> M(N);

	vector<int> end_point_guesses(N);
	iota(end_point_guesses.begin(), end_point_guesses.end(),0);
	shuffle(end_point_guesses.begin(),end_point_guesses.end(), rng);

	vector<int> res(N);
	for(const int& guess: end_point_guesses) 
	{
		for(int i = 0; i < N; i++)
			M[i] = i==guess ? 0 : 1;

		if(Query(M)==1)
		{
			res[0] = guess;
			break;
		}
	}
	vector<int> done(N,false);
	done[res[0]] = true;

	for(int i = 1; i < N; i++)
	{
		vector<int> candidates; candidates.reserve(N-i);
		for(int g = 0; g < N; g++)
			if(!done[g])
				candidates.push_back(g);
		shuffle(candidates.begin(),candidates.end(), rng);
		for(const int& guess : candidates)
		{
			for(int g = 0; g < N; g++)
				M[g] = g==res[i-1] || g==guess ? 1 : 0;
			if(Query(M)==1)
			{
				res[i] = guess;
				done[guess] = true;
				break;
			}
		}
	}
	for(int& g : res)
		++g;
	Answer(res);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...