답안 #886147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886147 2023-12-11T13:51:23 Z vjudge1 Toxic Gene (NOI23_toxic) C++17
37.2 / 100
17 ms 600 KB
#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;

inline set<int> whodied(vector<int> a) {
	if(a.size()>8) return {};
	vector<int> b;
	for(int i=0; i<a.size(); i++) {
		for(int j=0; j<(1<<i); j++) b.push_back(a[i]);
	}
	int c = query_sample(b);
	c = b.size()-c;
	set<int> ans;
	for(int i=0; i<8; i++) if(c&(1<<i)) ans.insert(a[i]);
	return ans;
}

inline set<int> whodied(vector<int> a, int b) {
	if(a.size()>8) return {};
	vector<int> d;
	for(int i=0; i<a.size(); i++) {
		for(int j=0; j<(1<<i); j++) d.push_back(a[i]);
	}
	d.push_back(b);
	int c = query_sample(d);
	c = d.size()-c;
	c--;
	set<int> ans;
	for(int i=0; i<8; i++) if(c&(1<<i)) ans.insert(a[i]);
	return ans;
} 

void determine_type(int n){
	set<int> strong, normal, toxic;
	vector<int> killable, killable4, killable2;

	queue<pair<int,int>> later;
	for(int i=1; i<=n; i+=8) {
		vector<int> cur;
		for(int j=i; j<min(i+8, n+1); j++) cur.push_back(j);
		set<int> curdead = whodied(cur);
		if(curdead.size()==0) {
			later.push({i, min(i+8-1, n)});
			continue;
		}
		for(int j=i; j<min(i+8, n+1); j++) {
			if(curdead.count(j)) killable.push_back(j);
			else strong.insert(j);
		}
	}
	int curi = 0;
	for(int i=0; i<killable.size(); i+=4) {
		vector<int> cur;
		for(int j=i; j<min(i+4, (int)killable.size()); j++) cur.push_back(killable[j]);
		set<int> curdead = whodied(cur);
		if(curdead.size()==0) {
			for(int j=i; j<min(i+4, (int)killable.size()); j++) {
				normal.insert(killable[j]);
			}
		}
		else {
			for(int j=i; j<min(i+4, (int)killable.size()); j++) killable4.push_back(killable[j]);
		}
	}
	curi = 0;

	for(int i=0; i<killable4.size(); i+=2) {
		if(curi == 30) {
			for(int j=i; j<min(i+2, (int)killable4.size()); j++) {
				normal.insert(killable4[j]);
			}
			continue;
		}
		vector<int> cur;
		for(int j=i; j<min(i+2, (int)killable4.size()); j++) cur.push_back(killable4[j]);
		set<int>curdead = whodied(cur);
		if(curdead.size()==0) {
			for(int j=i; j<min(i+2, (int)killable4.size()); j++) {
				normal.insert(killable4[j]);
			}
			if(i%4==0){
				for(int j=i+2; j<min(i+4, (int)killable4.size()); j++) killable2.push_back(killable4[j]);
				i+=2;
				curi++;
			}
		}
		else {
			for(int j=i; j<min(i+2, (int)killable4.size()); j++) killable2.push_back(killable4[j]);
			curi++;
		}
	}

	curi = 0;
	for(int i=0; i<killable2.size(); i++) {
		if(curi==30) {
			normal.insert(killable2[i]);
			continue;
		}
		vector<int> cur(1, killable2[i]);
		set<int> curdead = whodied(cur);
		if(curdead.size()==0){
			normal.insert(killable2[i]);
			if(i%2==0) {
				curi++;
				i++;
				if(i<killable2.size()) toxic.insert(killable2[i]);
			}
		}
		else{
			toxic.insert(killable2[i]);
			curi++;
		}
	}

	while(!later.empty()) {
		int l = later.front().first;
		int r = later.front().second;
		later.pop();
		vector<int> cur;
		for(int i=l; i<=r; i++) cur.push_back(i);
		set<int> curdead = whodied(cur, *toxic.begin());
		for(int i=l; i<=r; i++) {
			if(curdead.count(i)) normal.insert(i);
			else strong.insert(i);
		}
	}

	for(auto x:strong) answer_type(x, 'S');
	for(auto x:normal) answer_type(x, 'R');
	for(auto x:toxic) answer_type(x, 'T');
}

Compilation message

toxic.cpp: In function 'std::set<int> whodied(std::vector<int>)':
toxic.cpp:8:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i=0; i<a.size(); i++) {
      |               ~^~~~~~~~~
toxic.cpp: In function 'std::set<int> whodied(std::vector<int>, int)':
toxic.cpp:21:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i=0; i<a.size(); i++) {
      |               ~^~~~~~~~~
toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i=0; i<killable.size(); i+=4) {
      |               ~^~~~~~~~~~~~~~~~
toxic.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i=0; i<killable4.size(); i+=2) {
      |               ~^~~~~~~~~~~~~~~~~
toxic.cpp:94:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i=0; i<killable2.size(); i++) {
      |               ~^~~~~~~~~~~~~~~~~
toxic.cpp:106:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     if(i<killable2.size()) toxic.insert(killable2[i]);
      |        ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Partially correct 14 ms 516 KB Partially correct
3 Partially correct 10 ms 348 KB Partially correct
4 Partially correct 10 ms 508 KB Partially correct
5 Partially correct 12 ms 344 KB Partially correct
6 Partially correct 17 ms 600 KB Partially correct
7 Partially correct 11 ms 348 KB Partially correct
8 Partially correct 11 ms 348 KB Partially correct
9 Partially correct 11 ms 344 KB Partially correct
10 Partially correct 11 ms 348 KB Partially correct
11 Partially correct 10 ms 516 KB Partially correct
12 Partially correct 11 ms 348 KB Partially correct
13 Partially correct 11 ms 512 KB Partially correct
14 Partially correct 10 ms 348 KB Partially correct
15 Partially correct 11 ms 348 KB Partially correct
16 Partially correct 11 ms 344 KB Partially correct
17 Partially correct 11 ms 600 KB Partially correct
18 Partially correct 11 ms 348 KB Partially correct
19 Partially correct 11 ms 348 KB Partially correct
20 Partially correct 11 ms 516 KB Partially correct
21 Partially correct 10 ms 344 KB Partially correct
22 Correct 9 ms 520 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 10 ms 344 KB Output is correct
25 Correct 10 ms 516 KB Output is correct
26 Correct 10 ms 512 KB Output is correct
27 Correct 15 ms 600 KB Output is correct
28 Correct 9 ms 348 KB Output is correct
29 Correct 10 ms 348 KB Output is correct
30 Correct 10 ms 348 KB Output is correct
31 Correct 10 ms 344 KB Output is correct
32 Correct 10 ms 348 KB Output is correct
33 Correct 10 ms 348 KB Output is correct
34 Partially correct 11 ms 516 KB Partially correct
35 Partially correct 11 ms 348 KB Partially correct
36 Partially correct 2 ms 344 KB Partially correct