답안 #831523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831523 2023-08-20T10:09:46 Z MadokaMagicaFan 도서관 (JOI18_library) C++14
100 / 100
417 ms 336 KB
#include "bits/stdc++.h"
#include "library.h"
using namespace std;
#define pb push_back
#define sz(v) ((int)v.size())

mt19937 rng(time(NULL));

vector<int> ans, j;

bitset<1001> in;

int query(int s, vector<int> &z) {
	shuffle(z.begin(), z.end(), rng);
	if (sz(z) == 1) {
		fill(j.begin(), j.end(), 0);
		j[s-1] = 1; j[z.back()-1] = 1;
		if (Query(j) != 1)
			return -1;
		else
			return z[0];
	}
	if (sz(z) == 0) return -1;
	int l = 0;
	int r = sz(z) - 1;
	int c1, c2;


	while (l < r) {
		int m = (l+r)/2;
		fill(j.begin(), j.end(), 0);
		for (int i = l; i <= m; ++i)
			j[z[i]-1] = 1;
		c1 = Query(j);
		j[s-1] = 1;
		c2 = Query(j);
		if (c1 >= c2)
			r = m;
		else
			l = m+1;
	}

	if (l == sz(z) -1) {
		fill(j.begin(), j.end(), 0);
		j[s-1] = 1; j[z.back()-1] = 1;
		if (Query(j) != 1)
			return -1;
	}

	return z[l];
}

void remain(vector<int> &u, int n) {
	u.clear();
	for (int i = 1; i <= n; ++i)
		if (!in[i]) u.pb(i);
}

void Solve(int n) {
	int c = 1;
	j.assign(n, 0);
	vector<int> u;

	while (c != -1) {
		in[c] = 1;
		ans.pb(c);
		remain(u, n);
		c = query(c, u);
	}

	reverse(ans.begin(), ans.end());
	c = ans.back();
	ans.pop_back();
	while (c != -1) {
		in[c] = 1;
		ans.pb(c);
		remain(u, n);
		c = query(c, u);
	}

	Answer(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 256 KB # of queries: 2398
2 Correct 24 ms 208 KB # of queries: 2387
3 Correct 32 ms 208 KB # of queries: 2525
4 Correct 31 ms 208 KB # of queries: 2504
5 Correct 27 ms 208 KB # of queries: 2504
6 Correct 38 ms 208 KB # of queries: 2523
7 Correct 31 ms 208 KB # of queries: 2513
8 Correct 38 ms 208 KB # of queries: 2423
9 Correct 36 ms 208 KB # of queries: 2509
10 Correct 14 ms 284 KB # of queries: 1466
11 Correct 1 ms 208 KB # of queries: 0
12 Correct 1 ms 252 KB # of queries: 1
13 Correct 1 ms 208 KB # of queries: 4
14 Correct 1 ms 208 KB # of queries: 8
15 Correct 2 ms 208 KB # of queries: 73
16 Correct 3 ms 256 KB # of queries: 187
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 256 KB # of queries: 2398
2 Correct 24 ms 208 KB # of queries: 2387
3 Correct 32 ms 208 KB # of queries: 2525
4 Correct 31 ms 208 KB # of queries: 2504
5 Correct 27 ms 208 KB # of queries: 2504
6 Correct 38 ms 208 KB # of queries: 2523
7 Correct 31 ms 208 KB # of queries: 2513
8 Correct 38 ms 208 KB # of queries: 2423
9 Correct 36 ms 208 KB # of queries: 2509
10 Correct 14 ms 284 KB # of queries: 1466
11 Correct 1 ms 208 KB # of queries: 0
12 Correct 1 ms 252 KB # of queries: 1
13 Correct 1 ms 208 KB # of queries: 4
14 Correct 1 ms 208 KB # of queries: 8
15 Correct 2 ms 208 KB # of queries: 73
16 Correct 3 ms 256 KB # of queries: 187
17 Correct 396 ms 300 KB # of queries: 17132
18 Correct 347 ms 300 KB # of queries: 16980
19 Correct 372 ms 320 KB # of queries: 17156
20 Correct 263 ms 296 KB # of queries: 16009
21 Correct 313 ms 296 KB # of queries: 15015
22 Correct 333 ms 296 KB # of queries: 17159
23 Correct 368 ms 296 KB # of queries: 17168
24 Correct 105 ms 292 KB # of queries: 7845
25 Correct 354 ms 300 KB # of queries: 16725
26 Correct 417 ms 336 KB # of queries: 15634
27 Correct 123 ms 252 KB # of queries: 7776
28 Correct 340 ms 296 KB # of queries: 17142
29 Correct 324 ms 300 KB # of queries: 17136
30 Correct 331 ms 304 KB # of queries: 17206