Submission #168227

# Submission time Handle Problem Language Result Execution time Memory
168227 2019-12-12T03:29:09 Z dimash241 Library (JOI18_library) C++17
Compilation error
0 ms 0 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';
	assert(all.size() > 0);
	
	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++;
	if (sz(ans) == n - 1) {
		cout << "wtf";
		exit(0);
	}

	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) {
       ~~^~~~~~~~~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:129:6: error: 'sz' was not declared in this scope
  if (sz(ans) == n - 1) {
      ^~