답안 #58187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58187 2018-07-17T06:16:54 Z 정원준(#1691) 도서관 (JOI18_library) C++11
컴파일 오류
0 ms 0 KB
#include "library.h"
#include <bits/stdc++.h>
#define L long long

using namespace std;

//int Query(const vector<int>&M);
//void Answer(const vector<int>&res);

int ans[1010],chk[1010];

int f(int pos,int s,int e,vector<int>&get,vector<int>&input){
	/*printf("f %d %d %d\n",pos,s,e);
	for(int i=s;i<=e;i++)
	{
		printf("%d ",get[i]);
	}
	puts("");*/
	if(s==e) return get[s];
	int mid=(s+e)/2,i,temp1,temp2;
	
	for(i=s;i<=mid;i++)
	{
		input[get[i]]=1;
	}
	/*printf("input ");
	for(i=0;i<5;i++)
		printf("%d ",input[i]);
	puts("");*/
	temp1=Query(input);
	//printf("%d\n",temp1);
	input[ans[pos-1]]=0;
	/*printf("input ");
	for(i=0;i<5;i++)
		printf("%d ",input[i]);
	puts("");*/
	temp2=Query(input);
	//printf("%d\n",temp2);
	input[ans[pos-1]]=1;
	for(i=s;i<=mid;i++)
	{
		input[get[i]]=0;
	}
	if(temp1!=temp2) return f(pos,s,mid,get,input);
	else return f(pos,mid+1,e,get,input);
	
}

void Solve(int N){
	int i,j,start,secon;
	vector<int>input(N,0);
	for(i=0;i<N;i++)
	{
		input[i]=1;
	}
	for(i=0;i<N;i++)
	{
		input[i]=0;
		int temp=Query(input);
		input[i]=1;
		if(temp==1)
		{
			start=i;
			break;
		}
	}
	ans[0]=start;
	//printf("start %d\n",start);
	chk[start]=1;
	vector<int>input3(N,0);
	input3[start]=1;
	for(i=0;i<N;i++)
	{
		if(i!=start)
		{
			input3[i]=1;
			int temp=Query(input3);
			input3[i]=0;
			if(temp==1)
			{
				secon=i;
				break;
			}
		}
	}
	ans[1]=secon;
	chk[secon]=1;
	//printf("second %d\n",secon);
	
	for(i=2;i<N;i++)
	{
		vector<int>give;
		vector<int>input2(N,0);
		for(j=0;j<N;j++)
		{
			if(!chk[j]) give.push_back(j);
			else input2[j]=1;
		} 
		int temp=f(i,0,give.size()-1,give,input2);//���� i���� �پ��ִ� ���Ҹ� ã�´�. 
		ans[i]=temp;
		chk[temp]=1;
	}
	
	vector<int>giveans;
	for(i=0;i<N;i++)
	{
		giveans.push_back(ans[i]+1);
	}
	Answer(giveans);
}


int n,a[1010],chk2[1010],loc[1010];

int Query(const vector<int>&M){
	int i,ret=0;
	for(i=0;i<n;i++)
	{
		chk2[i]=0;
	}
	for(i=0;i<n;i++)
	{
		if(M[i]) chk2[loc[i]]=1;
	}
	for(i=0;i<n;i++)
	{
		if(chk2[i])
		{
			if(i==0||!chk2[i-1]) ret++;
		}
	}
	return ret;
}

void Answer(const vector<int>&res){
	int i;
	for(i=0;i<n;i++)
	{
		printf("%d ",res[i]);
	}
	return;
}

/*
int main()
{
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		loc[a[i]-1]=i;
	}
	Solve(n);
}*/

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:67:8: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ans[0]=start;
  ~~~~~~^~~~~~
library.cpp:86:8: warning: 'secon' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ans[1]=secon;
  ~~~~~~^~~~~~
/tmp/ccDZuQWJ.o: In function `Query(std::vector<int, std::allocator<int> > const&)':
library.cpp:(.text+0x0): multiple definition of `Query(std::vector<int, std::allocator<int> > const&)'
/tmp/ccaof9hd.o:grader.cpp:(.text+0x130): first defined here
/tmp/ccDZuQWJ.o: In function `Answer(std::vector<int, std::allocator<int> > const&)':
library.cpp:(.text+0x220): multiple definition of `Answer(std::vector<int, std::allocator<int> > const&)'
/tmp/ccaof9hd.o:grader.cpp:(.text+0x480): first defined here
collect2: error: ld returned 1 exit status