#ifndef NAM
#include "toxic.h"
#endif // NAM
#include <bits/stdc++.h>
using namespace std;
#ifdef NAM
string s;
int cnt_q,ch[301];
int query_sample(vector <int> species){
cnt_q++;
if (species.size()>300){
cout << "Error: Species size too large";
exit(0);
}
bool has_toxic=0;
int cnt=0;
for (int i:species)
if (s[i-1]=='T')
has_toxic=1;
for (int i:species)
cnt+=(s[i-1]=='S'||(s[i-1]=='R'&&!has_toxic));
return cnt;
}
void answer_type(int x, char c){
if (ch[x]){
cout << "Answer position " << x << "twice";
exit(0);
}
ch[x]=1;
if (s[x-1]!=c){
cout << "Wrong answer on character " << x;
exit(0);
}
}
#endif // NAM
vector <int> toxic,non_toxic;
int T[301];
int ask(int l, int r){
vector <int> v;
for (int i=l;i<=r;i++)
v.push_back(i);
return query_sample(v);
}
void solve(int l, int r){
if (ask(l,r)==r-l+1)
return;
if (l>r)
return;
int lo=l,hi=r-1,kq=r;
while (lo<=hi){
int mid=(lo+hi)>>1;
if (ask(l,mid)<mid-l+1){
kq=mid;
hi=mid-1;
}
else
lo=mid+1;
}
toxic.push_back(kq);
T[kq]=1;
solve(kq+1,r);
}
void determine_type(int n){
memset(T,0,sizeof(T));
toxic.clear();
non_toxic.clear();
int sz=8;
for (int i=1;i<=n;i+=sz)
solve(i,min(i+sz-1,n));
for (int i:toxic)
answer_type(i,'T');
for (int i=1;i<=n;i++)
if (!T[i])
non_toxic.push_back(i);
for (int j=0;j<non_toxic.size();j+=8){
vector <int> ve;
for (int i=0;i<8&&i+j<non_toxic.size();i++)
for (int k=0;k<(1<<i);k++)
ve.push_back(non_toxic[i+j]);
ve.push_back(toxic[0]);
int x=query_sample(ve);
for (int i=0;i<8&&i+j<non_toxic.size();i++)
answer_type(non_toxic[i+j],((x>>i)&1?'S':'R'));
}
}
#ifdef NAM
int main(){
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
//cin >> s;
int tc=100,mx=0;
while (tc--){
s="";
cnt_q=0;
memset(ch,0,sizeof(ch));
vector <int> tmp;
for (int i=0;i<300;i++){
s+=(rd()&1?'R':'S');
tmp.push_back(i);
}
for (int i=0;i<30;i++)
s[rd()%s.size()]='T';
determine_type(s.size());
for (int i=1;i<=s.size();i++)
if (!ch[i]){
cerr << "Didn't answer position " << i;
exit(0);
}
mx=max(mx,cnt_q);
}
cout << "You used " << mx << " queries";
}
#endif // NAM
Compilation message
toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int j=0;j<non_toxic.size();j+=8){
| ~^~~~~~~~~~~~~~~~~
toxic.cpp:77:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int i=0;i<8&&i+j<non_toxic.size();i++)
| ~~~^~~~~~~~~~~~~~~~~
toxic.cpp:82:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int i=0;i<8&&i+j<non_toxic.size();i++)
| ~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Partially correct |
4 ms |
348 KB |
Partially correct |
3 |
Partially correct |
4 ms |
348 KB |
Partially correct |
4 |
Partially correct |
4 ms |
348 KB |
Partially correct |
5 |
Partially correct |
4 ms |
508 KB |
Partially correct |
6 |
Partially correct |
4 ms |
344 KB |
Partially correct |
7 |
Partially correct |
4 ms |
344 KB |
Partially correct |
8 |
Partially correct |
5 ms |
348 KB |
Partially correct |
9 |
Partially correct |
4 ms |
348 KB |
Partially correct |
10 |
Partially correct |
5 ms |
348 KB |
Partially correct |
11 |
Partially correct |
5 ms |
500 KB |
Partially correct |
12 |
Partially correct |
4 ms |
348 KB |
Partially correct |
13 |
Partially correct |
4 ms |
348 KB |
Partially correct |
14 |
Partially correct |
5 ms |
348 KB |
Partially correct |
15 |
Partially correct |
4 ms |
344 KB |
Partially correct |
16 |
Partially correct |
4 ms |
348 KB |
Partially correct |
17 |
Partially correct |
5 ms |
348 KB |
Partially correct |
18 |
Partially correct |
4 ms |
348 KB |
Partially correct |
19 |
Partially correct |
5 ms |
348 KB |
Partially correct |
20 |
Partially correct |
5 ms |
348 KB |
Partially correct |
21 |
Partially correct |
5 ms |
348 KB |
Partially correct |
22 |
Partially correct |
4 ms |
348 KB |
Partially correct |
23 |
Partially correct |
4 ms |
348 KB |
Partially correct |
24 |
Partially correct |
4 ms |
348 KB |
Partially correct |
25 |
Partially correct |
4 ms |
348 KB |
Partially correct |
26 |
Partially correct |
4 ms |
348 KB |
Partially correct |
27 |
Partially correct |
4 ms |
348 KB |
Partially correct |
28 |
Partially correct |
4 ms |
348 KB |
Partially correct |
29 |
Partially correct |
4 ms |
348 KB |
Partially correct |
30 |
Partially correct |
4 ms |
344 KB |
Partially correct |
31 |
Partially correct |
4 ms |
348 KB |
Partially correct |
32 |
Partially correct |
4 ms |
508 KB |
Partially correct |
33 |
Partially correct |
4 ms |
348 KB |
Partially correct |
34 |
Partially correct |
4 ms |
348 KB |
Partially correct |
35 |
Partially correct |
4 ms |
508 KB |
Partially correct |
36 |
Partially correct |
1 ms |
348 KB |
Partially correct |