답안 #1080233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080233 2024-08-29T08:12:05 Z Tozzyyyy 도서관 (JOI18_library) C++14
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2000;
vector<int> adj[MAXN];
vector<int> res;
int vs[MAXN];
void dfs(int u){
	vs[u] = 1;
	res.push_back(u);
	for(auto x : adj[u]) if(vs[x] == 0) dfs(x);
}
void Solve(int n)
{
	int cur = 1;	
	int cnt = 0;
	vector<int> check(n+1);
	while(cnt < n - 1){
		vector<int> t;
		for(int j = 1 ; j <= n ; j++){
			if(cur == j or check[j]) continue;
			t.push_back(j);
		}

		int l = 0 , r = t.size()-1;
		int res = -1;
		while(l <= r){
			int mid = l + r  >> 1;
			vector<int> m(n);
			for(int j = l ; j <=mid ; j++) m[t[j] - 1] = 1;
			int c1 = Query(m);
			m[cur-1] = 1;
			int c2 = Query(m);
			if(c2 <= c1) res = mid , r = mid-1;
			else l = mid+1;
		}
		if(res == -1){
			check[cur] = 1;
			cur = 1;
		}else{
			check[cur] = 1;
			res = t[res];
			adj[cur].push_back(res);
			adj[res].push_back(cur);
			cur = res, cnt++;
		}

	}
	
	int res , mn = 2000;
	for(int i = 1; i <= n ; i++){
		if(adj[i].size() < mn){
			mn = adj[i].size();
			res = i;
		}
	}
	dfs(res);
	Answer(res);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:31:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |    int mid = l + r  >> 1;
      |              ~~^~~
library.cpp:55:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |   if(adj[i].size() < mn){
      |      ~~~~~~~~~~~~~~^~~~
library.cpp:61:9: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'int'
   61 |  Answer(res);
      |         ^~~
In file included from library.cpp:3:
library.h:3:37: note: in passing argument 1 of 'void Answer(const std::vector<int>&)'
    3 | void Answer(const std::vector<int>& res);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~