Submission #940953

# Submission time Handle Problem Language Result Execution time Memory
940953 2024-03-08T03:02:36 Z socpite Toxic Gene (NOI23_toxic) C++17
0 / 100
1 ms 600 KB
#include<bits/stdc++.h>
#include"toxic.h"
using namespace std;

mt19937 rng(69420);

int query_sample(vector<int> species);

int h[301];

int shuffled_query(vector<int> speices){
	for(auto &v: speices)v = h[v];
	return query_sample(speices);
}

void shuffled_answer(int x, char c){
	answer_type(h[x], c);
}

void determine_type(int n){
    int l = 1, r = n;
	iota(h+1, h+n+1, 1);
	// shuffle(h+1, h+n+1, rng);
    vector<int> vec(n);
    vector<bool> done(n+1, 0);
    iota(vec.begin(), vec.end(), 1);
    while(l < r){
        int mid = (l+r)>>1;
		int tmp = shuffled_query(vector<int>(vec.begin() + l - 1, vec.begin() + mid));
        if(tmp != mid - l + 1)r = mid;
        else l = mid+1;
    }
    vec.erase(vec.begin() + l - 1);
    shuffled_answer(l, 'T');
    int d = 0;
    vector<int> sampling;
    vector<int> species;
	vector<int> missing;
    for(int i = 0; i < vec.size(); i++){
        if(species.size() + (1<<d) < 300){
            for(int _ = 0; _ < (1<<d); _++)species.push_back(vec[i]);
            sampling.push_back(vec[i]);
            d++;
        }
        else {
            int tot1 = shuffled_query(species);
			if(tot1 == species.size()){
				species.push_back(l);
				int tot2 = shuffled_query(species);
				for(int j = 0; j < sampling.size(); j++){
					if(tot2&(1<<j)){
						shuffled_answer(sampling[j], 'S');
						done[sampling[j]] = 1;
					}
					else shuffled_answer(sampling[j], 'R');
				}
			}
			else {
			// cout << tot1 << " " << tot2 << endl;
				for(int j = 0; j < sampling.size(); j++){
					if(tot1&(1<<j)){
						shuffled_answer(sampling[j], 'S');
						done[sampling[j]] = 1;
					}
					else {
						missing.push_back(sampling[j]);
					}
				}
			}	
			sampling = {vec[i]};
			species = {vec[i]};
			d = 1;
        }
    }
	int tot1 = shuffled_query(species);
	if(tot1 == species.size()){
		species.push_back(l);
		int tot2 = shuffled_query(species);
		for(int j = 0; j < sampling.size(); j++){
			if(tot2&(1<<j)){
				shuffled_answer(sampling[j], 'S');
				done[sampling[j]] = 1;
			}
			else shuffled_answer(sampling[j], 'R');
		}
	}
	else {
	// cout << tot1 << " " << tot2 << endl;
		for(int j = 0; j < sampling.size(); j++){
			if(tot1&(1<<j)){
				shuffled_answer(sampling[j], 'S');
				done[sampling[j]] = 1;
			}
			else {
				missing.push_back(sampling[j]);
			}
		}
	}
	while(missing.size() > 100){
		shuffle(missing.begin(), missing.end(), rng);
		if(shuffled_query(vector<int>(missing.begin(), missing.begin() + missing.size()/8))){
			missing.erase(missing.begin(), missing.begin() + missing.size()/8);
			break;
		}
	}
	for(auto v: missing){
		if(shuffled_query({v}))shuffled_answer(v, 'R');
		else shuffled_answer(v, 'T');
	}
}

Compilation message

toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i = 0; i < vec.size(); i++){
      |                    ~~^~~~~~~~~~~~
toxic.cpp:47:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    if(tot1 == species.size()){
      |       ~~~~~^~~~~~~~~~~~~~~~~
toxic.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int j = 0; j < sampling.size(); j++){
      |                    ~~^~~~~~~~~~~~~~~~~
toxic.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int j = 0; j < sampling.size(); j++){
      |                    ~~^~~~~~~~~~~~~~~~~
toxic.cpp:76:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  if(tot1 == species.size()){
      |     ~~~~~^~~~~~~~~~~~~~~~~
toxic.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int j = 0; j < sampling.size(); j++){
      |                  ~~^~~~~~~~~~~~~~~~~
toxic.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for(int j = 0; j < sampling.size(); j++){
      |                  ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -