Submission #58724

# Submission time Handle Problem Language Result Execution time Memory
58724 2018-07-19T03:15:46 Z ksun48 Library (JOI18_library) C++14
Compilation error
0 ms 0 KB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;

int check(int n, int a, int b){
	vector<int> ask(n, 0);
	ask[a] = ask[b] = 1;
	if(Query(ask) == 1){
		return 1;
	}
	return 0;
}

void Solve(int N) {
	int n = N;
	vector<vector<int> > groups;
	for(int i = 0; i < n; i++){
		groups.push_back({i});
	}
	while(groups.size() > 1){
		vector<int> inside(groups.size(), 1);
		int n1 = groups.size();
		while(n1 > 2){
			vector<int> newinside(groups.size());
			vector<int> ask(n, 0);
			int newn1 = 0;
			int b = sqrt(n1) + 1;
			for(int i = 0; i < groups.size(); i++){
				if(inside[i]){
					newinside[i] = (rand() % b == 0);
					if(newinside[i]){
						newn1++;
					}
				}
			}
			if(newn1 <= 1 || newn1 == n1) continue;
			for(int i = 0; i < groups.size(); i++){
				if(newinside[i]){
					for(int a : groups[i]){
						ask[a] = 1;
					}
				}
			}
			int b = Query(ask);
			//assert(b <= newn1);
			if(b < newn1){
				n1 = newn1;
				inside = newinside;
			}
		}
		vector<vector<int> > newgroups;
		vector<vector<int> > good;
		for(int i = 0; i < groups.size(); i++){
			if(!inside[i]){
				newgroups.push_back(groups[i]);
			} else {
				good.push_back(groups[i]);
			}
		}
		vector<int> ans;
		if(check(n, good[0][0], good[1][0])){
			reverse(good[0].begin(), good[0].end());
		} else if(check(n, good[0][good[0].size() - 1], good[1][0])){
		} else if(check(n, good[0][0], good[1][good[1].size()-1])){
			reverse(good[0].begin(), good[0].end());
			reverse(good[1].begin(), good[1].end());
		} else if(check(n, good[0][good[0].size() - 1], good[1][good[1].size() - 1])){
			reverse(good[1].begin(), good[1].end());			
		} else {
			//assert(0);
		}
		ans.insert(ans.end(), good[0].begin(), good[0].end());
		ans.insert(ans.end(), good[1].begin(), good[1].end());
		newgroups.push_back(ans);
		groups = newgroups;
	}
	vector<int> ans = groups[0];
	for(int j = 0; j < ans.size(); j++){
		ans[j]++;
		//cout << ans[j] << " ";
	}
	//cout << endl;
	Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < groups.size(); i++){
                   ~~^~~~~~~~~~~~~~~
library.cpp:37:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0; i < groups.size(); i++){
                   ~~^~~~~~~~~~~~~~~
library.cpp:44:8: error: redeclaration of 'int b'
    int b = Query(ask);
        ^
library.cpp:27:8: note: 'int b' previously declared here
    int b = sqrt(n1) + 1;
        ^
library.cpp:53:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < groups.size(); i++){
                  ~~^~~~~~~~~~~~~~~
library.cpp:78:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < ans.size(); j++){
                 ~~^~~~~~~~~~~~