답안 #267215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
267215 2020-08-16T01:29:46 Z Shisuko 도서관 (JOI18_library) C++14
19 / 100
2000 ms 504 KB
#include <cstdio>
#include <chrono>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include "library.h"
using namespace std;

void Solve(int N)
{
	if(N==1)
	{
		Answer({1});
		return;
	}
	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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 256 KB # of queries: 10797
2 Correct 134 ms 256 KB # of queries: 9505
3 Correct 144 ms 256 KB # of queries: 10004
4 Correct 135 ms 256 KB # of queries: 10357
5 Correct 146 ms 256 KB # of queries: 10533
6 Correct 140 ms 256 KB # of queries: 10236
7 Correct 147 ms 256 KB # of queries: 9947
8 Correct 127 ms 256 KB # of queries: 8441
9 Correct 123 ms 256 KB # of queries: 9110
10 Correct 59 ms 256 KB # of queries: 4034
11 Correct 0 ms 256 KB # of queries: 0
12 Correct 0 ms 256 KB # of queries: 2
13 Correct 0 ms 256 KB # of queries: 4
14 Correct 1 ms 256 KB # of queries: 5
15 Correct 1 ms 256 KB # of queries: 70
16 Correct 3 ms 256 KB # of queries: 206
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 256 KB # of queries: 10797
2 Correct 134 ms 256 KB # of queries: 9505
3 Correct 144 ms 256 KB # of queries: 10004
4 Correct 135 ms 256 KB # of queries: 10357
5 Correct 146 ms 256 KB # of queries: 10533
6 Correct 140 ms 256 KB # of queries: 10236
7 Correct 147 ms 256 KB # of queries: 9947
8 Correct 127 ms 256 KB # of queries: 8441
9 Correct 123 ms 256 KB # of queries: 9110
10 Correct 59 ms 256 KB # of queries: 4034
11 Correct 0 ms 256 KB # of queries: 0
12 Correct 0 ms 256 KB # of queries: 2
13 Correct 0 ms 256 KB # of queries: 4
14 Correct 1 ms 256 KB # of queries: 5
15 Correct 1 ms 256 KB # of queries: 70
16 Correct 3 ms 256 KB # of queries: 206
17 Execution timed out 3100 ms 504 KB Time limit exceeded
18 Halted 0 ms 0 KB -