제출 #1163682

#제출 시각아이디문제언어결과실행 시간메모리
1163682shraefkt도서관 (JOI18_library)C++20
0 / 100
36 ms416 KiB
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;



void Solve(int N)
{
	vector<int> M(N);
	
	for(int i = 0; i < N; i++) {
		M[i] = 1;
	}
	vector<int> res(N,0);
	int ans;
	bool  done = false;
	int a,b;
	int found[N+1] ={0};
	for (int i=0;i<N;i++) {
		M[i] = 0;
		ans = Query(M);
		M[i] = 1;
		if (ans == 1) {
			if (done) {
				res[N-1] = i+1;
				b = i+1;
				break;
			}
			res[0] = i+1;
			a = i+1;
			done = true;
		}
	}
	found[a] = 1;
	found[b] = 1;
	int rounds = N/2;
	int candidates[2];
	for (int j=1;j<rounds;j++) {
		M[a-1] = 0;
		M[b-1] = 0;
		int beginning = j;
		int ending = N-j-1;
		done = false;
		for (int i=0;i<N;i++) {
			if (found[i+1]!=0) continue;
			M[i] = 0;
			ans = Query(M);
			M[i] = 1;
			if (ans == 1) {
				if (done) {
					candidates[1] = i+1; 
					found[i+1] =1;
					break;
				}
				candidates[0] = i+1;
				found[i+1] = 1;
				done = true;
			}
		}
		//determine which side, a is on the left side
		M[a-1]  = 1;
		M[candidates[0]-1] = 0;
		ans = Query(M);
		M[a-1]  = 0;
		M[candidates[0]-1] = 0;
		M[candidates[1]-1] = 0;
		if (ans == 2) {
			a = res[beginning] = candidates[0];
			b = res[ending] = candidates[1];
			
		} else {
			a = res[beginning] = candidates[1];
			b = res[ending] = candidates[0];
		}
	}
	for (int i=0;i<N;i++) {
		if (found[i+1] == 0) res[N/2] = i+1;
	}
	Answer(res);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...