답안 #775581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775581 2023-07-06T14:25:22 Z rxlfd314 도서관 (JOI18_library) C++17
19 / 100
236 ms 4288 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;

void Solve(int N) {
	if (N == 1) {
		Answer({1});
		return;
	}
	if (N == 2) {
		Answer({1, 2});
		return;
	}

	vector<int> cc[N];
	for (int i = 0; i < N; i++) {
		cc[i].resize(N);
		iota(cc[i].begin(), cc[i].end(), 0);
		cc[i].erase(find(cc[i].begin(), cc[i].end(), i));
	}
	
	int ae[N], s = -1, q_cnt = N;
	for (int i = 0; i < N; i++) {
		vector<int> vec(N, 1);
		vec[i] = 0;
		ae[i] = Query(vec) < 2;
		s = ae[i] ? s : i;
	}
	
	vector<int> adj[N];
	auto findBest = [&](int i) {
		int lo = 0, hi = cc[i].size()-1;
		while (lo < hi) {
			int mid = lo + hi >> 1;
			vector<int> vec(N);
			for (int j = 0; j <= mid; j++) {
				vec[cc[i][j]] = 1;
			}
			if (++q_cnt > 20000) exit(0);
			int q = Query(vec);
			vec[i] = 1;
			if (++q_cnt > 20000) exit(0);
			q - Query(vec) < 0 ? lo = mid + 1 : hi = mid;
		}
		if (lo == cc[i].size()) return -1;
		int j = cc[i][lo];
		adj[i].push_back(j);
		adj[j].push_back(i);
		cc[j].erase(find(cc[j].begin(), cc[j].end(), i));
		cc[i].erase(find(cc[i].begin(), cc[i].end(), j));
		return j;
	};
	for (int cur = s; cur >= 0 && !ae[cur]; cur = findBest(cur));
	for (int cur = s; cur >= 0 && !ae[cur]; cur = findBest(cur));

	for (int i = 0; i < N; i++) {
		if (adj[i].size() < 2) {
			vector<int> ans(N);
			ans[0] = i;
			for (int j = 1, x = adj[i][0]; j < N; j++) {
				ans[j] = x;
				for (int k : adj[x]) {
					x = k == ans[j-1] ? x : k;
				}
			}
			for (int &j : ans) {
				j++;
			}
			Answer(ans);
			return;
		}
	}
}

Compilation message

library.cpp: In lambda function:
library.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |    int mid = lo + hi >> 1;
      |              ~~~^~~~
library.cpp:45:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   if (lo == cc[i].size()) return -1;
      |       ~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 336 KB # of queries: 3132
2 Correct 34 ms 428 KB # of queries: 3105
3 Correct 37 ms 452 KB # of queries: 3268
4 Correct 37 ms 336 KB # of queries: 3278
5 Correct 34 ms 464 KB # of queries: 3272
6 Correct 33 ms 448 KB # of queries: 3284
7 Correct 31 ms 464 KB # of queries: 3272
8 Correct 35 ms 336 KB # of queries: 3123
9 Correct 34 ms 336 KB # of queries: 3241
10 Correct 23 ms 352 KB # of queries: 1921
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 0
13 Correct 1 ms 272 KB # of queries: 5
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 2 ms 208 KB # of queries: 125
16 Correct 3 ms 208 KB # of queries: 277
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 336 KB # of queries: 3132
2 Correct 34 ms 428 KB # of queries: 3105
3 Correct 37 ms 452 KB # of queries: 3268
4 Correct 37 ms 336 KB # of queries: 3278
5 Correct 34 ms 464 KB # of queries: 3272
6 Correct 33 ms 448 KB # of queries: 3284
7 Correct 31 ms 464 KB # of queries: 3272
8 Correct 35 ms 336 KB # of queries: 3123
9 Correct 34 ms 336 KB # of queries: 3241
10 Correct 23 ms 352 KB # of queries: 1921
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 0
13 Correct 1 ms 272 KB # of queries: 5
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 2 ms 208 KB # of queries: 125
16 Correct 3 ms 208 KB # of queries: 277
17 Incorrect 236 ms 4288 KB Unexpected end of file - token expected
18 Halted 0 ms 0 KB -