답안 #168226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168226 2019-12-12T03:26:28 Z dimash241 도서관 (JOI18_library) C++17
0 / 100
544 ms 504 KB
#include<bits/stdc++.h>
#include "library.h"

#define F first
#define S second
#define pb push_back 
using namespace std;

bool SEND = 1;
                                         
int n, a[2222];

int ask (const std::vector < int > &m) {
	if (SEND) {
		return Query(m);
	}

	int n = (int)m.size();
	int res = 0;
	for (int i = 0, j = 0; i < n; i ++) {
		j = i;
		while (j < n && m[a[j]]) j ++;

		if (m[a[i]]) {
			res ++;
//			cerr << i << ' ' << j << '\n';
		}	

		i = j;
	}
	/*cerr << "Que " << res << '\n';
	for (auto it : m) {
		cerr << it << ' ';
	}
	cout << '\n'; */
	assert(res > 0);
	return res;
}


void print (const std:: vector <int> &res) {
	if (SEND) {
		Answer(res);

	} else {
		for (auto x : res)
			cout << x << ' ';
		cout << '\n';
		exit(0);	
	}
}

int go (int n, int x, vector < int > &vec) {
	vector < int > all;
	for (int i = 0; i < n; i ++) if (vec[i]) {
		all.pb(i);
	}
	//cerr << all.size() << ' ' << x << '\n';
	
	
	if (all.size() == 1) {
		return all.back();
	}

	vector < int > p1(n, 0);
	vector < int > p2(n, 0);

	for (int i = 0; i < all.size(); i ++) {
		if (i < all.size() / 2) {
			p1[all[i]] = 1;
	//		cerr << all[i] << " r :";
		} else {
			p2[all[i]] = 1;
	//		cerr << all[i] << " w :";
		}
	}

	int was = ask(p1);
	//cerr << was << '\n';
	p1[x] = 1;

	if (ask(p1) == was) {
		p1[x] = 0;
	//	cerr << "tur1\n";
		return go(n, x, p1);
	}

	//cerr << "tur2\n";
	return go(n, x, p2);
}

void Solve(int n) {
	if (n == 1) {
		print({1});
		return;
	}
	if (n == 2) {
		print({2});
		return;
	}
	vector < int > m(n, 1);
	int start = -1;
	for (int i = 0; i < n; i ++) {
		m[i] = 0;

		if (ask(m) == 1) {
			start = i;
			break;
			
		}

		m[i] = 1;
	}
	vector < int > ans;
	ans.pb(start);
//	cout << start << '\n';
//	exit(0);

	for (int i = 1; i < n; i ++) {
		vector < int > vec(n, 1);
		for (auto x : ans) vec[x] = 0;
		
		int x = go(n, ans.back(), vec);
	//	cout << i << ' ' << x << '\n';
		ans.pb(x);
	}

	for (auto &to : ans) to++;

	print(ans);
}



// B...a

Compilation message

library.cpp: In function 'int go(int, int, std::vector<int>&)':
library.cpp:68:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < all.size(); i ++) {
                  ~~^~~~~~~~~~~~
library.cpp:69:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i < all.size() / 2) {
       ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 320 KB # of queries: 2375
2 Correct 40 ms 316 KB # of queries: 2409
3 Correct 53 ms 248 KB # of queries: 2648
4 Correct 36 ms 248 KB # of queries: 2595
5 Correct 32 ms 316 KB # of queries: 2508
6 Correct 53 ms 376 KB # of queries: 2551
7 Correct 46 ms 376 KB # of queries: 2544
8 Correct 43 ms 376 KB # of queries: 2420
9 Correct 45 ms 376 KB # of queries: 2546
10 Correct 28 ms 248 KB # of queries: 1474
11 Correct 2 ms 248 KB # of queries: 0
12 Incorrect 2 ms 376 KB Wrong Answer [4]
13 Correct 2 ms 376 KB # of queries: 4
14 Correct 2 ms 248 KB # of queries: 7
15 Correct 3 ms 248 KB # of queries: 77
16 Correct 5 ms 248 KB # of queries: 183
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 320 KB # of queries: 2375
2 Correct 40 ms 316 KB # of queries: 2409
3 Correct 53 ms 248 KB # of queries: 2648
4 Correct 36 ms 248 KB # of queries: 2595
5 Correct 32 ms 316 KB # of queries: 2508
6 Correct 53 ms 376 KB # of queries: 2551
7 Correct 46 ms 376 KB # of queries: 2544
8 Correct 43 ms 376 KB # of queries: 2420
9 Correct 45 ms 376 KB # of queries: 2546
10 Correct 28 ms 248 KB # of queries: 1474
11 Correct 2 ms 248 KB # of queries: 0
12 Incorrect 2 ms 376 KB Wrong Answer [4]
13 Correct 2 ms 376 KB # of queries: 4
14 Correct 2 ms 248 KB # of queries: 7
15 Correct 3 ms 248 KB # of queries: 77
16 Correct 5 ms 248 KB # of queries: 183
17 Correct 544 ms 504 KB # of queries: 17982
18 Correct 498 ms 424 KB # of queries: 17293
19 Correct 474 ms 420 KB # of queries: 17467
20 Correct 476 ms 412 KB # of queries: 16325
21 Correct 407 ms 452 KB # of queries: 15324
22 Correct 528 ms 448 KB # of queries: 17669
23 Correct 496 ms 452 KB # of queries: 17224
24 Correct 170 ms 320 KB # of queries: 7915
25 Correct 508 ms 504 KB # of queries: 17136
26 Correct 460 ms 412 KB # of queries: 15963
27 Correct 170 ms 248 KB # of queries: 8040
28 Correct 477 ms 412 KB # of queries: 15957
29 Correct 462 ms 424 KB # of queries: 15939
30 Correct 481 ms 412 KB # of queries: 15957