답안 #267221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
267221 2020-08-16T01:36:21 Z Shisuko 도서관 (JOI18_library) C++14
19 / 100
2000 ms 392 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 g = 0; g < N; g++)
		M[g] = 0;

	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);
		
		M[res[i-1]] = 1;
		for(const int& guess : candidates)
		{
			M[guess] = 1;
			if(Query(M)==1)
			{
				res[i] = guess;
				done[guess] = true;
				break;
			}
			M[guess] = 0;
		}
		M[res[i-1]] = 0;
	}
	for(int& g : res)
		++g;
	Answer(res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 256 KB # of queries: 9714
2 Correct 121 ms 256 KB # of queries: 9115
3 Correct 138 ms 256 KB # of queries: 9855
4 Correct 106 ms 256 KB # of queries: 11090
5 Correct 145 ms 384 KB # of queries: 9800
6 Correct 126 ms 256 KB # of queries: 10092
7 Correct 143 ms 256 KB # of queries: 9971
8 Correct 125 ms 256 KB # of queries: 9227
9 Correct 120 ms 256 KB # of queries: 9145
10 Correct 56 ms 256 KB # of queries: 4086
11 Correct 0 ms 256 KB # of queries: 0
12 Correct 0 ms 256 KB # of queries: 2
13 Correct 1 ms 256 KB # of queries: 3
14 Correct 0 ms 256 KB # of queries: 7
15 Correct 1 ms 256 KB # of queries: 72
16 Correct 4 ms 256 KB # of queries: 187
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 256 KB # of queries: 9714
2 Correct 121 ms 256 KB # of queries: 9115
3 Correct 138 ms 256 KB # of queries: 9855
4 Correct 106 ms 256 KB # of queries: 11090
5 Correct 145 ms 384 KB # of queries: 9800
6 Correct 126 ms 256 KB # of queries: 10092
7 Correct 143 ms 256 KB # of queries: 9971
8 Correct 125 ms 256 KB # of queries: 9227
9 Correct 120 ms 256 KB # of queries: 9145
10 Correct 56 ms 256 KB # of queries: 4086
11 Correct 0 ms 256 KB # of queries: 0
12 Correct 0 ms 256 KB # of queries: 2
13 Correct 1 ms 256 KB # of queries: 3
14 Correct 0 ms 256 KB # of queries: 7
15 Correct 1 ms 256 KB # of queries: 72
16 Correct 4 ms 256 KB # of queries: 187
17 Execution timed out 3040 ms 392 KB Time limit exceeded
18 Halted 0 ms 0 KB -