Submission #347825

#TimeUsernameProblemLanguageResultExecution timeMemory
347825jamielim도서관 (JOI18_library)C++14
0 / 100
47 ms492 KiB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;

int n;
vector<int> ans;

void dnc(int idx,vector<int> rem){
	if(SZ(rem)==1){
		ans[idx]=rem[0]+1;
		return;
	}
	int m=(SZ(rem)-1)/2;
	vector<int> q;
	for(int i=0;i<n;i++)q.pb(0);
	for(int i=0;i<=m;i++)q[rem[i]]=1;
	int cur=Query(q);
	for(int i=0;i<idx;i++)q[ans[i]-1]=1;
	if(cur==Query(q)){
		vector<int> l;
		for(int i=0;i<=m;i++)l.pb(rem[i]);
		dnc(idx,l);
	}else{
		vector<int> r;
		for(int i=m+1;i<SZ(rem);i++)r.pb(rem[i]);
		dnc(idx,r);
	}
}

void Solve(int N){
	n=N;
	ans.resize(n);
	vector<int> m(N);
	for(int i=0;i<n;i++)m[i]=1;
	for(int i=0;i<n;i++){
		m[i]=0;
		if(Query(m)==1){
			ans[0]=i+1;
			vector<int> v;
			for(int j=0;j<n;j++)if(j!=i)v.pb(j);
			//printf("%d ",ans[0]);
			for(int j=1;j<n;j++){
				dnc(j,v);
				vector<int> temp;
				for(int k=0;k<SZ(v);k++){
					if(v[k]==ans[j]-1)continue;
					temp.pb(v[k]);
				}
				v=temp;
				//printf("%d ",ans[j]);
			}
			Answer(ans);
			return;
		}
		m[i]=1;
	}
}
/*
5
4
2
5
3
1

9
7
2
1
6
4
8
3
9
5
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...