답안 #329207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
329207 2020-11-19T21:08:52 Z NachoLibre 도서관 (JOI18_library) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#include "library.h"

/*int p[100] = {5, 3, 4, 1, 2};

int Query(vector<bool> v, int x) {
}*/

const int N = 1003;
int e[N][2];
vector<bool> qv;

int ask(vector<int> v) {
	for(int i = 0; i < qv.size(); ++i) qv[i] = 0;
	for(int i = 0; i <  v.size(); ++i) qv[v[i] - 1] = 1;
	return Query(qv);
}

bool neig(vector<int> v, int x) {
	int a = ask(v);
	v.push_back(x);
	int b = ask(v);
	v.pop_back();
	return(a >= b);
}

void dvd(vector<int> &v, int x) {
	int n = v.size();
	vector<int> l;
	for(int i = 0; i < n / 2; ++i) {
		l.push_back(v[i]);
	}
	if(neig(l, x)) v = l;
	else {
		l.clear();
		for(int i = n / 2; i < n; ++i) {
			l.push_back(v[i]);
		}
		v = l;
	}
}

void Solve(int n) {
	qv.resize(n);
	vector<int> v;
	for(int i = 2; i <= n; ++i) {
		v.push_back(i);
	}
	int dg = 1;
	while(true) {
		vector<int> u = v;
		while(u.size() > 1) {
			dvd(u, dg);
		}
		if(neig(u, dg)) {
			e[dg][0] = u[0];
			e[u[0]][1] = dg;
			dg = u[0];
			v.erase(find(v.begin(), v.end(), u[0]));
		} else {
			break;
		}
	}
	dg = 1;
	while(v.size()) {
		vector<int> u = v;
		while(u.size() > 1) {
			dvd(u, dg);
		}
		e[dg][1] = u[0];
		e[u[0]][0] = dg;
		dg = u[0];
		v.erase(find(v.begin(), v.end(), u[0]));
	}
	dg = 1;
	while(e[dg][0]) dg = e[dg][0];
	while(dg) {
		v.push_back(dg);
		dg = e[dg][1];
	}
	Answer(v);
}

/*int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	return 0;
}*/

Compilation message

library.cpp: In function 'int ask(std::vector<int>)':
library.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i = 0; i < qv.size(); ++i) qv[i] = 0;
      |                 ~~^~~~~~~~~~~
library.cpp:16:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i = 0; i <  v.size(); ++i) qv[v[i] - 1] = 1;
      |                 ~~^~~~~~~~~~~
library.cpp:17:15: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<bool>'
   17 |  return Query(qv);
      |               ^~
In file included from library.cpp:3:
library.h:2:35: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
    2 | int Query(const std::vector<int>& M);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^