답안 #1079971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079971 2024-08-29T05:14:57 Z vjudge1 도서관 (JOI18_library) C++17
100 / 100
225 ms 344 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;

#define isz(a) (int)(a).size()

void Solve(int N){
	if (N == 1){
		Answer({1});
		return;
	}
	if (N == 2){
		Answer({1, 2});
		return;
	}
	vector <int> p(N);
	for (int i = 0; i < N; i++){
		vector <int> arr = {};
		for (int j = 0; j < N; j++)
			if (j == i) arr.push_back(0); else arr.push_back(1);
		if (Query(arr) == 1){
			p[0] = i;
			break;
		}
	}
	for (int i = 0; i < N; i++){
		if (i == p[0]) continue;
		vector <int> arr = {};
		for (int j = 0; j < N; j++)
			if (j == p[0] || j == i) arr.push_back(1); else arr.push_back(0);
		if (Query(arr) == 1){
			p[1] = i;
			break;
		}
	}
	bool mark[N];
	memset(mark, 0, sizeof(mark));
	mark[p[0]] = mark[p[1]] = 1;
	for (int i = 2; i < N; i++){
		vector <int> rem = {};
		for (int j = 0; j < N; j++)
			if (!mark[j]) rem.push_back(j);
		int l = 0, r = isz(rem)-2, res = isz(rem)-1;
		while (l <= r){
			int mid = (l+r)/2;
			vector <int> arr(N, 0);
			for (int j = 0; j < i; j++) arr[p[j]] = 1;
			for (int j = 0; j <= mid; j++) arr[rem[j]] = 1;
			int x = Query(arr), y;
			arr[p[i-1]] = 0;
			y = Query(arr);
			if (x < y){
				res = mid;
				r = mid-1;
			}
			else l = mid+1;
		}
		p[i] = rem[res];
		mark[p[i]] = 1;
	}
	for (int i = 0; i < N; i++) p[i]++;
	Answer(p);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 344 KB # of queries: 2367
2 Correct 25 ms 344 KB # of queries: 2570
3 Correct 19 ms 344 KB # of queries: 2668
4 Correct 26 ms 344 KB # of queries: 2740
5 Correct 21 ms 344 KB # of queries: 2600
6 Correct 21 ms 344 KB # of queries: 2726
7 Correct 26 ms 344 KB # of queries: 2708
8 Correct 26 ms 344 KB # of queries: 2575
9 Correct 17 ms 344 KB # of queries: 2662
10 Correct 13 ms 344 KB # of queries: 1534
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 0
13 Correct 1 ms 344 KB # of queries: 3
14 Correct 1 ms 344 KB # of queries: 5
15 Correct 1 ms 344 KB # of queries: 79
16 Correct 2 ms 344 KB # of queries: 192
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 344 KB # of queries: 2367
2 Correct 25 ms 344 KB # of queries: 2570
3 Correct 19 ms 344 KB # of queries: 2668
4 Correct 26 ms 344 KB # of queries: 2740
5 Correct 21 ms 344 KB # of queries: 2600
6 Correct 21 ms 344 KB # of queries: 2726
7 Correct 26 ms 344 KB # of queries: 2708
8 Correct 26 ms 344 KB # of queries: 2575
9 Correct 17 ms 344 KB # of queries: 2662
10 Correct 13 ms 344 KB # of queries: 1534
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 0 ms 344 KB # of queries: 0
13 Correct 1 ms 344 KB # of queries: 3
14 Correct 1 ms 344 KB # of queries: 5
15 Correct 1 ms 344 KB # of queries: 79
16 Correct 2 ms 344 KB # of queries: 192
17 Correct 218 ms 344 KB # of queries: 18495
18 Correct 214 ms 344 KB # of queries: 18249
19 Correct 208 ms 344 KB # of queries: 17590
20 Correct 225 ms 344 KB # of queries: 17148
21 Correct 199 ms 344 KB # of queries: 16194
22 Correct 219 ms 344 KB # of queries: 18259
23 Correct 222 ms 344 KB # of queries: 18188
24 Correct 98 ms 340 KB # of queries: 8235
25 Correct 219 ms 344 KB # of queries: 17736
26 Correct 193 ms 344 KB # of queries: 16233
27 Correct 92 ms 344 KB # of queries: 8526
28 Correct 169 ms 344 KB # of queries: 15940
29 Correct 190 ms 344 KB # of queries: 15922
30 Correct 197 ms 344 KB # of queries: 15940