제출 #1161312

#제출 시각아이디문제언어결과실행 시간메모리
1161312emptypringlescan도서관 (JOI18_library)C++20
0 / 100
9 ms436 KiB
#include <bits/stdc++.h>
using namespace std;
#include "library.h"
vector<pair<int,int> > eds;
vector<int> adj[1005];
int numgrp(vector<int> x){
	int ans=0;
	for(int i:x) if(i) ans++;
	for(auto i:eds){
		if(x[i.first]&&x[i.second]) ans--;
	}
	return ans;
}
vector<int> ans;
void dfs(int x, int p){
	ans.push_back(x+1);
	for(int i:adj[x]){
		if(i==p) continue;
		dfs(i,x);
	}
}
void Solve(int n){
  eds.clear(); ans.clear();
  for(int i=0; i<=n; i++) adj[i].clear();
	vector<int> tst(n,0);
	for(int i=2; i<=n; i++){
		for(int j=0; j<i; j++) tst[j]=1;
		int x=Query(tst),y=numgrp(tst);
		if(x==y) continue;
		if(x==y-1){
			int lo=0,hi=i-2,mid;
			while(lo<hi){
				mid=(lo+hi)/2;
				for(int j=0; j<=mid; j++) tst[j]=0;
				for(int j=mid+1; j<i-1; j++) tst[j]=1;
				x=Query(tst),y=numgrp(tst);
				if(x==y-1) lo=mid+1;
				else hi=mid;
			}
			eds.push_back({lo,i-1});
		}
		else{
			assert(x==y-2);
			int lo=0,hi=i-2,mid;
			while(lo<hi){
				mid=(lo+hi)/2;
				for(int j=0; j<=mid; j++) tst[j]=0;
				for(int j=mid+1; j<i-1; j++) tst[j]=1;
				x=Query(tst),y=numgrp(tst);
				if(x==y-1) lo=mid+1;
				else hi=mid;
			}
			eds.push_back({lo,i-1});
			lo=0,hi=i-2,mid;
			while(lo<hi){
				mid=(lo+hi)/2;
				for(int j=0; j<=mid; j++) tst[j]=0;
				for(int j=mid+1; j<i-1; j++) tst[j]=1;
				x=Query(tst),y=numgrp(tst);
				if(x==y-1) lo=mid+1;
				else hi=mid;
			}
			eds.push_back({lo,i-1});
		}
	}
	for(auto i:eds){
		adj[i.first].push_back(i.second);
		adj[i.second].push_back(i.first);
	}
	for(int i=0; i<n; i++){
		if((int)adj[i].size()==1){
			dfs(i,-1);
			break;
		}
	}
	Answer(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...