Submission #1185178

#TimeUsernameProblemLanguageResultExecution timeMemory
1185178NotLinuxToxic Gene (NOI23_toxic)C++20
42.12 / 100
5 ms328 KiB
#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void determine_type(int n){
	int perm[n];
	vector<int>ans(n+1,-1);
	iota(perm , perm + n , 1);
	shuffle(perm , perm + n , rng);
	int toxic;
	{
		int l = 0 , r = n-1;
		while(l < r){
			int mid = (l + r) / 2;
			vector<int>vec;
			for(int j = l;j<=mid;j++)vec.push_back(perm[j]);
			if(query_sample(vec) == mid-l+1){
				l = mid+1;
			}
			else {
				r = mid;
			}
		}
		toxic = perm[l];
	}
	// eliminate the strong ones
	for(int i = 0;i<n;i+=8){
		vector<int>vec;
		int bruh = 0;
		for(int j = 0;j<8;j++){
			if(i+j>=n)continue;
			int tmp = 1 << j;
			bruh += tmp;
			while(tmp--)vec.push_back(perm[i+j]);
		}
		vec.push_back(toxic);
		int cevap = query_sample(vec);
		if(cevap == bruh){// S ve R lerden olusan grup
			vec.push_back(toxic);
			cevap = query_sample(vec);
			for(int j = 0;j<8;j++){
				if(i+j>=n)continue;
				if(cevap & (1 << j))ans[perm[i+j]] = 2;
				else ans[perm[i+j]] = 0;
			}
		}
		else{// T S R
			for(int j = 0;j<8;j++){
				if(cevap & (1 << j))ans[perm[i+j]] = 2;
			}
		}
	}
	vector<int>v;
	for(int i = 0;i<n;i++)
		if(ans[perm[i]] == -1)
			v.push_back(perm[i]);
	shuffle(v.begin() , v.end() , rng);
	
	const int BSZ = 8;
	for(int i = 0;i<v.size();i+=BSZ){
		vector<int>vec;
		for(int j = i;j<min((int)v.size() , i+BSZ);j++){
			vec.push_back(v[j]);
		}
		while(!vec.empty() and query_sample(vec) == 0){
			int l = 0 , r = vec.size()-1;
			while(l < r){
				int mid = (l + r) / 2;
				vector<int>bruh;
				for(int k = l;k<=mid;k++)
					bruh.push_back(vec[k]);
				if(query_sample(bruh))l = mid+1;
				else r = mid;
			}
			ans[vec[l]] = 1;
			vec.erase(vec.begin() + l);
		}
		for(auto itr : vec)
			ans[itr] = 0;
	}

	for(int i = 1;i<=n;i++){
		if(ans[i] == 0){
			answer_type(i,'R');
			// cout << "R";
		}
		else if(ans[i] == 1){
			answer_type(i,'T');
			// cout << "T";
		}
		else {
			answer_type(i,'S');
			// cout << "S";
		}
	}
	// cout << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...