Submission #1306662

#TimeUsernameProblemLanguageResultExecution timeMemory
1306662TymondLibrary (JOI18_library)C++20
0 / 100
14 ms332 KiB
#include "library.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

vi used;
int n;

int join(int x){
	vi nused = {};
	for(int j = 1; j <= n; j++){
		if(!used[j]){
			nused.pb(j);
		}
	}

	int l = 0;
	int p = sz(nused);
	int mid;
	while(l < p){
		mid = (l + p) / 2;
		vi M(n, 0);
		for(int j = 0; j <= mid; j++){
			M[nused[j] - 1] = 1;
		}

		for(int j = 1; j <= n; j++){
			if(used[j]){
				M[j - 1] = 1;
			}
		}

		int r1 = Query(M);
		M[x - 1] = 0;
		int r2 = Query(M);
		if(r1 == r2){
			l = mid + 1;
		}else{
			p = mid;
		}
	}
	return (l == sz(nused) ? n + 1 : nused[l]);
}

void Solve(int N){
	n = N;
	used.assign(n + 1, 0);

	vi p;
	vi ends = {};
	for(int i = n; i >= 1; i--){
		p = {i};
		used[i] = 1;
		while(true && sz(p) < n){
			bool f = false;
			for(auto ele : ends){
				if(ele == p.back()){
					f = true;
				}
			}

			if(f){
				break;
			}

			int x = join(p.back());
			if(x == n + 1){
				break;
			}
			used[x] = 1;
			p.pb(x);
		}

		if(sz(p) == 1){
			ends.pb(i);
			p.clear();
			used[i] = 0;
		}else{
			break;
		}
	}
	
	if(sz(p) == 0){
		Answer(ends);
		return;
	}

	reverse(all(p));

	while(sz(p) < n){
		int x = join(p.back());
		used[x] = 1;
		p.pb(x);
	}

	Answer(p);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...