#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> T;
vector<vector<int>> finding_nemo;
vector<int> vec(n);
vector<bool> bad(n+1, 0);
vector<bool> done(n+1, 0);
iota(vec.begin(), vec.end(), 1);
// vector<int> missing;
int tcnt = 0;
while(!vec.empty()){
// shuffle(vec.begin(), vec.end(), rng);
vector<int> sampling;
vector<int> species;
vector<int> missing;
for(int i = 0; i < min<int>(8, vec.size()); i++){
sampling.push_back(vec[i]);
for(int _ = 0; _ < (1<<i); _++)species.push_back(vec[i]);
}
for(int i = 0; i < sampling.size(); i++)vec.erase(vec.begin());
// cout << "????" << endl;
int tot1 = shuffled_query(species);
if(tot1 == species.size()){
finding_nemo.push_back(sampling);
}
else {
for(int i = 0; i < sampling.size(); i++){
if(tot1&(1<<i)){
shuffled_answer(sampling[i], 'S');
}
else missing.push_back(sampling[i]);
}
int ql = 0, r = missing.size()-1;
while(ql < r){
int mid = (ql+r)>>1;
vector<int> nw(missing.begin(), missing.begin() + mid + 1);
if(!finding_nemo.empty()){
vector<int> old_sampling = finding_nemo.back();
for(int i = 0; i < old_sampling.size(); i++){
for(int _ = 0; _ < (1<<i); _++)nw.push_back(old_sampling[i]);
}
}
int tmp = shuffled_query(nw);
if(tmp != nw.size()){
r = mid;
if(!finding_nemo.empty()){
vector<int> old_sampling = finding_nemo.back();
finding_nemo.pop_back();
for(int i = 0; i < old_sampling.size(); i++){
if(tmp&(1<<i))shuffled_answer(old_sampling[i], 'S');
else shuffled_answer(old_sampling[i], 'R');
}
}
}
else ql = mid+1;
}
tcnt++;
for(int i = 0; i <= ql; i++){
if(i < ql)shuffled_answer(missing[i], 'R');
else {
shuffled_answer(missing[i], 'T');
T.push_back(missing[i]);
}
}
for(int i = ql+1; i < missing.size(); i++){
bad[missing[i]] = 1;
vec.push_back(missing[i]);
}
}
}
// cout << T.back() << endl;
for(auto old_sampling: finding_nemo){
vector<int> nw;
for(int i = 0; i < old_sampling.size(); i++){
for(int _ = 0; _ < (1<<i); _++)nw.push_back(old_sampling[i]);
}
nw.push_back(T.back());
int tmp = shuffled_query(nw);
for(int i = 0; i < old_sampling.size(); i++){
if(tmp&(1<<i))shuffled_answer(old_sampling[i], 'S');
else shuffled_answer(old_sampling[i], 'R');
}
}
}
Compilation message
toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < sampling.size(); i++)vec.erase(vec.begin());
| ~~^~~~~~~~~~~~~~~~~
toxic.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | if(tot1 == species.size()){
| ~~~~~^~~~~~~~~~~~~~~~~
toxic.cpp:48:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < sampling.size(); i++){
| ~~^~~~~~~~~~~~~~~~~
toxic.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i = 0; i < old_sampling.size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~
toxic.cpp:65:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | if(tmp != nw.size()){
| ~~~~^~~~~~~~~~~~
toxic.cpp:70:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < old_sampling.size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~
toxic.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int i = ql+1; i < missing.size(); i++){
| ~~^~~~~~~~~~~~~~~~
toxic.cpp:95:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int i = 0; i < old_sampling.size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~
toxic.cpp:100:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int i = 0; i < old_sampling.size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~~~
toxic.cpp:21:9: warning: unused variable 'l' [-Wunused-variable]
21 | int l = 1, r = n;
| ^
toxic.cpp:21:16: warning: unused variable 'r' [-Wunused-variable]
21 | int l = 1, r = n;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
11 ms |
348 KB |
Output is correct |
3 |
Correct |
11 ms |
600 KB |
Output is correct |
4 |
Correct |
11 ms |
520 KB |
Output is correct |
5 |
Correct |
12 ms |
348 KB |
Output is correct |
6 |
Correct |
12 ms |
348 KB |
Output is correct |
7 |
Correct |
12 ms |
344 KB |
Output is correct |
8 |
Correct |
12 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
11 ms |
348 KB |
Output is correct |
11 |
Correct |
10 ms |
348 KB |
Output is correct |
12 |
Correct |
12 ms |
344 KB |
Output is correct |
13 |
Correct |
11 ms |
348 KB |
Output is correct |
14 |
Correct |
10 ms |
344 KB |
Output is correct |
15 |
Correct |
12 ms |
524 KB |
Output is correct |
16 |
Partially correct |
12 ms |
348 KB |
Partially correct |
17 |
Correct |
12 ms |
492 KB |
Output is correct |
18 |
Partially correct |
12 ms |
344 KB |
Partially correct |
19 |
Correct |
12 ms |
348 KB |
Output is correct |
20 |
Correct |
11 ms |
520 KB |
Output is correct |
21 |
Correct |
10 ms |
348 KB |
Output is correct |
22 |
Correct |
9 ms |
348 KB |
Output is correct |
23 |
Correct |
9 ms |
600 KB |
Output is correct |
24 |
Correct |
12 ms |
348 KB |
Output is correct |
25 |
Partially correct |
11 ms |
348 KB |
Partially correct |
26 |
Correct |
12 ms |
520 KB |
Output is correct |
27 |
Correct |
11 ms |
348 KB |
Output is correct |
28 |
Correct |
10 ms |
348 KB |
Output is correct |
29 |
Correct |
12 ms |
348 KB |
Output is correct |
30 |
Correct |
12 ms |
520 KB |
Output is correct |
31 |
Correct |
12 ms |
348 KB |
Output is correct |
32 |
Correct |
11 ms |
348 KB |
Output is correct |
33 |
Correct |
10 ms |
348 KB |
Output is correct |
34 |
Partially correct |
12 ms |
348 KB |
Partially correct |
35 |
Correct |
19 ms |
588 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |