답안 #826134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826134 2023-08-15T10:35:13 Z model_code Toxic Gene (NOI23_toxic) C++17
43.9294 / 100
13 ms 412 KB
#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
typedef pair<int, int> ii;
 
vector<int> toquery;
int query(){
	return query_sample(toquery);
}
 
deque<int> an;
deque<int> nt;
deque<int> unknown;
int onetoxic = -1;
set<int> antidode;
 
bool checkunknown(vector<int> elements){
	if(sz(elements) == 0) return false;
		
	toquery.clear();
	
	for(int i = 0;i < sz(elements);i++){
		for(int j = 0;j < (1 << i);j++) toquery.push_back(elements[i]);
	}
	
	int cnt = min(sz(an), 8-sz(elements));
	for(int i = 0;i < cnt;i++){
		for(int j = 0;j < (1 << (i+sz(elements)));j++) toquery.push_back(an[i]);
	}
		
	int res = query_sample(toquery);
	if(res == sz(toquery)){
		return false;
	}
	else{
		for(int i = 0;i < sz(elements);i++){
			if(res & (1 << i)){
				answer_type(elements[i], 'S');
				antidode.insert(elements[i]);
			}
		}
		for(int i = 0;i < cnt;i++){ ///piggybacking
			if(res & (1 << (i+sz(elements)))) answer_type(an[0], 'S');
			else answer_type(an[0], 'R');
			an.pop_front();
		}
		return true;
	}
}
 
bool checknt(vector<int> elements){
	if(sz(elements) == 0) return false;
		
	toquery.clear();
	
	for(int i = 0;i < sz(elements);i++){
		toquery.push_back(elements[i]);
	}
	
	int cnt = min(sz(an), 8);
	for(int i = 0;i < cnt;i++){
		for(int j = 0;j < (1 << i);j++) toquery.push_back(an[i]);
	}
		
	int res = query_sample(toquery);
	if(res == sz(toquery)){
		return false;
	}
	else{
		for(int i = 0;i < cnt;i++){ ///piggybacking
			if(res & (1 << i)) answer_type(an[0], 'S');
			else answer_type(an[0], 'R');
			an.pop_front();
		}
		return true;
	}
}
 
void bsta(vector<int> elements){ ///assuming inside this group already got something bad
	if(sz(elements) == 0) return;
	if(sz(elements) == 1){
		onetoxic = elements[0];
		answer_type(elements[0], 'T');
		return;
	}
	
	vector<int> newelements;
	for(int x : elements) if(antidode.find(x) == antidode.end()) newelements.push_back(x);
	
	int mid = sz(newelements) / 2;
	
	vector<int> L, R;
	for(int i = 0;i < mid;i++){
		L.push_back(newelements[i]);
	}
	for(int i = mid;i < sz(newelements);i++){
		R.push_back(newelements[i]);
	}
	
	if(checknt(L)){ ///L have toxic
		for(int x : R) nt.push_back(x);
		bsta(L);
	}
	else{ ///L don't have toxic
		for(int x : L) answer_type(x, 'R');
		bsta(R);
	}
}
 
 
void determine_type(int n){
	an.clear(); unknown.clear(); antidode.clear();
	for(int i = 1;i <= n;i++) unknown.push_back(i);
	random_shuffle(all(unknown));
	
	while(sz(unknown) > 0){
		//show(sz(unknown));
		
		int batchsize = min(7, sz(unknown));
		vector<int> totest;
		for(int i = 0;i < batchsize;i++){
			totest.push_back(unknown[0]);
			unknown.pop_front();
		}
		
		if(checkunknown(totest)) bsta(totest);
		else{
			for(int x : totest) an.push_back(x);
		}
	}
	
	while(sz(nt) > 0){
		int batchsize = min(8, sz(nt));
		vector<int> totest;
		for(int i = 0;i < batchsize;i++){
			totest.push_back(nt[0]);
			nt.pop_front();
		}
		
		if(checknt(totest)) bsta(totest);
		else{
			for(int x : totest) answer_type(x, 'R');
		}
	}
	
	//if(current_tc % 100 == 0) show(sz(an));
	while(sz(an) > 0){
		checknt({onetoxic});
	}
  for(int i=0;i<50;i++) query();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Partially correct 9 ms 340 KB Partially correct
3 Partially correct 9 ms 376 KB Partially correct
4 Partially correct 9 ms 340 KB Partially correct
5 Partially correct 10 ms 340 KB Partially correct
6 Partially correct 9 ms 372 KB Partially correct
7 Partially correct 10 ms 376 KB Partially correct
8 Partially correct 12 ms 340 KB Partially correct
9 Partially correct 10 ms 376 KB Partially correct
10 Partially correct 12 ms 376 KB Partially correct
11 Partially correct 11 ms 384 KB Partially correct
12 Partially correct 9 ms 376 KB Partially correct
13 Partially correct 9 ms 340 KB Partially correct
14 Partially correct 10 ms 380 KB Partially correct
15 Partially correct 11 ms 380 KB Partially correct
16 Partially correct 9 ms 376 KB Partially correct
17 Partially correct 9 ms 340 KB Partially correct
18 Partially correct 9 ms 340 KB Partially correct
19 Partially correct 10 ms 340 KB Partially correct
20 Partially correct 11 ms 404 KB Partially correct
21 Partially correct 10 ms 412 KB Partially correct
22 Partially correct 9 ms 408 KB Partially correct
23 Correct 8 ms 336 KB Output is correct
24 Partially correct 12 ms 400 KB Partially correct
25 Partially correct 11 ms 340 KB Partially correct
26 Partially correct 13 ms 400 KB Partially correct
27 Partially correct 11 ms 404 KB Partially correct
28 Partially correct 11 ms 408 KB Partially correct
29 Partially correct 9 ms 340 KB Partially correct
30 Partially correct 9 ms 400 KB Partially correct
31 Partially correct 10 ms 404 KB Partially correct
32 Partially correct 12 ms 396 KB Partially correct
33 Partially correct 11 ms 340 KB Partially correct
34 Partially correct 11 ms 400 KB Partially correct
35 Partially correct 9 ms 368 KB Partially correct
36 Partially correct 2 ms 212 KB Partially correct