#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
void answer(vector<bool> &res) {
cout<<"A ";
for (int i = 0; i < res.size(); ++i) {
if(res[i]) cout<<"1";
else cout<<"0";
}
cout<<endl;
string c; cin>>c;
if(c=="W") exit(0);
}
bool test(vector<int> &i,int n) {
cout<<"Q ";
vector<bool> t(n,false);
for(auto u:i) {
t[u]=true;
}
for(auto u:t) {
if(u) cout<<1;
else cout<<0;
}
cout<<endl;
string c; cin>>c;
return c=="P";
}
void check(vector<int> &n, vector<bool> &res,vector<int> &free,vector<int> &k,int N) {
if(n.size()==0) return;
if(n.size()==1) {
res[n[0]]=true;
return;
}
vector<int> toTest(k[n.size()]);
for (int i = 0; i < k[n.size()]; ++i) {
toTest[i]=n[i];
}
if(test(toTest,N)) {
check(toTest,res,free,k,N);
for (int i = k[n.size()]; i < n.size(); ++i) {
free.push_back(n[i]);
}
}else {
vector<int> u;
for (int i = k[n.size()]; i < n.size(); ++i) {
u.push_back(n[i]);
}
for (int i = 0; i < k[n.size()]; ++i) {
res[i]=false;
}
check(u,res,free,k,N);
}
}
int main()
{
cin.tie(0);
int N,T;
double p;
cin>>N>>p>>T;
int background = -1/log2(1-p);
if(background==0) background=1;
vector<int> k(N+1);
for (int i = 0; i < N+1; ++i) {
double d =(log2(1-(1-pow(1-p,i))/2)/log2(1-p));
k[i] = d;
if(k[i]==0)k[i]=1;
}
for (int mi = 0; mi < T; ++mi) {
vector<bool> res(N);
vector<int> free;
for (int i= 0; i < N; ++i) {
free.push_back(i);
}
while(!free.empty()) {
vector<int> o;
for (int i = 0; i < background; ++i) {
if(!free.empty()) {
o.push_back(free.back()); free.pop_back();
}
}
if(test(o,N)) {
check(o,res,free,k,N);
}else {
for (int i :o) {
res[i]=false;
}
}
}
answer(res);
}
}
Compilation message
Main.cpp: In function 'void answer(std::vector<bool>&)':
Main.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int i = 0; i < res.size(); ++i) {
| ~~^~~~~~~~~~~~
Main.cpp: In function 'void check(std::vector<int>&, std::vector<bool>&, std::vector<int>&, std::vector<int>&, int)':
Main.cpp:44:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = k[n.size()]; i < n.size(); ++i) {
| ~~^~~~~~~~~~
Main.cpp:49:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = k[n.size()]; i < n.size(); ++i) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
344 KB |
Output is correct |
2 |
Correct |
43 ms |
344 KB |
Output is correct |
3 |
Correct |
56 ms |
344 KB |
Output is correct |
4 |
Correct |
35 ms |
344 KB |
Output is correct |
5 |
Correct |
36 ms |
344 KB |
Output is correct |
6 |
Correct |
59 ms |
344 KB |
Output is correct |
7 |
Correct |
43 ms |
344 KB |
Output is correct |
8 |
Correct |
35 ms |
344 KB |
Output is correct |
9 |
Correct |
36 ms |
344 KB |
Output is correct |
10 |
Correct |
24 ms |
344 KB |
Output is correct |
11 |
Correct |
36 ms |
344 KB |
Output is correct |
12 |
Correct |
40 ms |
344 KB |
Output is correct |
13 |
Correct |
43 ms |
344 KB |
Output is correct |
14 |
Correct |
41 ms |
344 KB |
Output is correct |
15 |
Correct |
36 ms |
344 KB |
Output is correct |
16 |
Correct |
40 ms |
344 KB |
Output is correct |
17 |
Execution timed out |
7062 ms |
344 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
456 KB |
translate:wrong |
2 |
Halted |
0 ms |
0 KB |
- |