#include "toxic.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a.size())
mt19937 seed(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand2(int l,int r){return uniform_int_distribution<int>(l,r)(seed);}
vector<int>tox;
vector<int>leftover;
vector<int>notox;
int bquery(vector<int>v){
int ori = sz(v);
int c = min(8,sz(notox));
vector<int>add;
for(int i=0;i<c;i++){
int x = notox.back();
add.push_back(x);
notox.pop_back();
for(int j=0;j<(1<<i);j++)v.push_back(x);
}
int res = query_sample(v);
if(res == sz(v)){
for(int x:add)notox.push_back(x);
return ori;
}else{
for(int i=0;i<c;i++){
if(res & (1<<i))answer_type(add[i],'S');
else answer_type(add[i],'R');
}
return 0;
}
}
void find_toxic(vector<int>v){
// for(int x:v)cout<<x<<" ";
// cout<<'\n';
if(sz(v) == 1){
//cout<<v[0]<<'\n';
answer_type(v[0],'T');
tox.push_back(v[0]);
return;
}
int m = sz(v)/2;
vector<int>a,b;
for(int i=0;i<m;i++)a.push_back(v[i]);
for(int i=m;i<sz(v);i++)b.push_back(v[i]);
if(rand2(0,1))swap(a,b);
int res = bquery(a);
if(res == sz(a)){
for(int x:a)answer_type(x,'R');
find_toxic(b);
}
else {
for(int x:b)leftover.push_back(x);
find_toxic(a);
}
}
void determine_type(int n){
vector<int>p;
for(int i=1;i<=n;i++)p.push_back(i);
shuffle(p.begin(),p.end(),seed);
notox.clear();
tox.clear();
vector<vector<int>>maybe;
for(int i=1;i<=n;i+=8){
vector<int>v;
for(int j=0;j<8;j++){
if(i+j > n)break;
for(int k=0;k<(1<<j);k++)v.push_back(p[i+j-1]);
}
int res = query_sample(v);
if(res == sz(v)){
for(int j=0;j<8;j++){
if(i+j > n)break;
notox.push_back(p[i+j-1]);
}
}else{
vector<int>u;
for(int j=0;j<8;j++){
if(i+j > n)break;
if(res & (1<<j))answer_type(p[i+j-1],'S');
else u.push_back(p[i+j-1]);
}
maybe.push_back(u);
}
}
while(!maybe.empty()){
vector<int>v = maybe.back();
maybe.pop_back();
int lim = 8;
//if(sz(tox) >= 15)lim = 16;
if(sz(tox) >= 20)lim = 12;
while(!maybe.empty() && sz(v) + sz(maybe.back()) <= lim){
vector<int>u = maybe.back();
for(int x:u)v.push_back(x);
maybe.pop_back();
}
while(true){
leftover.clear();
find_toxic(v);
v = leftover;
if(v.empty())break;
if(bquery(v)){
for(int x:v)answer_type(x,'R');
break;
}
}
}
//query left out regular/strong
while(!notox.empty()){
vector<int>v;
int c = min(8,sz(notox));
vector<int>add;
for(int i=0;i<c;i++){
int x = notox.back();
add.push_back(x);
notox.pop_back();
for(int j=0;j<(1<<i);j++)v.push_back(x);
}
v.push_back(tox[0]);
int res = query_sample(v);
for(int i=0;i<c;i++){
if(res & (1<<i))answer_type(add[i],'S');
else answer_type(add[i],'R');
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
14 ms |
348 KB |
Output is correct |
3 |
Correct |
9 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
348 KB |
Output is correct |
5 |
Partially correct |
9 ms |
348 KB |
Partially correct |
6 |
Partially correct |
9 ms |
516 KB |
Partially correct |
7 |
Partially correct |
9 ms |
348 KB |
Partially correct |
8 |
Partially correct |
9 ms |
348 KB |
Partially correct |
9 |
Partially correct |
9 ms |
348 KB |
Partially correct |
10 |
Correct |
10 ms |
516 KB |
Output is correct |
11 |
Partially correct |
11 ms |
348 KB |
Partially correct |
12 |
Partially correct |
9 ms |
348 KB |
Partially correct |
13 |
Partially correct |
12 ms |
600 KB |
Partially correct |
14 |
Correct |
8 ms |
348 KB |
Output is correct |
15 |
Partially correct |
10 ms |
344 KB |
Partially correct |
16 |
Partially correct |
13 ms |
344 KB |
Partially correct |
17 |
Partially correct |
12 ms |
348 KB |
Partially correct |
18 |
Partially correct |
9 ms |
348 KB |
Partially correct |
19 |
Partially correct |
9 ms |
348 KB |
Partially correct |
20 |
Correct |
10 ms |
516 KB |
Output is correct |
21 |
Correct |
8 ms |
348 KB |
Output is correct |
22 |
Correct |
8 ms |
520 KB |
Output is correct |
23 |
Correct |
7 ms |
348 KB |
Output is correct |
24 |
Partially correct |
9 ms |
516 KB |
Partially correct |
25 |
Correct |
12 ms |
516 KB |
Output is correct |
26 |
Correct |
9 ms |
348 KB |
Output is correct |
27 |
Correct |
10 ms |
520 KB |
Output is correct |
28 |
Correct |
8 ms |
348 KB |
Output is correct |
29 |
Partially correct |
9 ms |
348 KB |
Partially correct |
30 |
Partially correct |
12 ms |
348 KB |
Partially correct |
31 |
Partially correct |
11 ms |
348 KB |
Partially correct |
32 |
Correct |
9 ms |
344 KB |
Output is correct |
33 |
Correct |
8 ms |
344 KB |
Output is correct |
34 |
Partially correct |
9 ms |
348 KB |
Partially correct |
35 |
Partially correct |
11 ms |
512 KB |
Partially correct |
36 |
Partially correct |
2 ms |
348 KB |
Partially correct |