This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<bool> VB;
int N;
double P;
bool test_students(std::vector<bool> mask) {
assert(mask.size() == (size_t)N);
std::string mask_str(N, ' ');
for (int i = 0; i < N; i++)
mask_str[i] = mask[i] ? '1' : '0';
printf("Q %s\n", mask_str.c_str());
fflush(stdout);
char answer;
scanf(" %c", &answer);
return answer == 'P';
}
map<ld, int> segsz = {
{1, 1000},
{5, 1000},
{11, 70},
{28, 30},
{39, 15},
{68, 10},
{104, 9},
{158, 9},
{200, 9}
};
VB find_positive() {
int n = N;
int cnt = segsz[int(1000*P)];
if (P > 0.2) {
VB answer(n);
rep(i, n) {
VB mask(n);
mask[i] = true;
if (test_students(mask)) answer[i] = true;
}
return answer;
} else {
VB answer(n);
int mek = int(1000 * P);
VPI seg;
for (int l = 0; l < n;) {
if (l+cnt > n-1) {
seg.pb({l, n-1});
break;
}
seg.pb({l, l+cnt});
l = l+cnt+1;
}
for (auto[L, R] : seg) {
int last = L-1;
while (true) {
if (int(1000*P) < 68) {
VB query(n);
replr(i, L, R) query[i] = (true && !answer[i]);
if (!test_students(query)) break;
}
int l = last, r = R+1;
while (l + 1 < r) {
int m = (l + r) / 2;
VB query(n);
replr(i, 0, m) query[i] = (true && !answer[i]);
bool f = test_students(query);
if (f) r = m;
else l = m;
}
if (r == R+1) break;
last = r;
answer[r] = true;
}
}
return answer;
}
return VB();
}
int main() {
int T;
scanf("%d %lf %d", &N, &P, &T);
for (int i = 0; i < T; i++) {
std::vector<bool> answer = find_positive();
assert(answer.size() == (size_t)N);
std::string answer_str(N, ' ');
for (int j = 0; j < N; j++)
answer_str[j] = answer[j] ? '1' : '0';
printf("A %s\n", answer_str.c_str());
fflush(stdout);
char verdict;
scanf(" %c", &verdict);
if (verdict == 'W')
exit(0);
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'VB find_positive()':
Main.cpp:86:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
86 | for (auto[L, R] : seg) {
| ^
Main.cpp:76:13: warning: unused variable 'mek' [-Wunused-variable]
76 | int mek = int(1000 * P);
| ^~~
Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf(" %c", &answer);
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:119:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | scanf("%d %lf %d", &N, &P, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:129:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | scanf(" %c", &verdict);
| ~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |