This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 1000
int min(int a, int b) { return a < b ? a : b; }
unsigned int Z = 12345;
int rand_() {
return (Z *= 3) >> 1;
}
int n, m; double p;
int query(int l, int r) {
static char cc[N + 1], s[2];
memset(cc, '0', n * sizeof *cc), memset(cc + l, '1', (r - l) * sizeof *cc);
printf("Q %s\n", cc), fflush(stdout);
scanf("%s", s);
return s[0] == 'P';
}
int main() {
int t, subtask;
scanf("%d%lf%d", &n, &p, &t), m = 1 / p * 2, subtask = t == 1 ? 1 : 2;
while (t--) {
static char cc[N + 1];
int i, l, r, lower, upper;
memset(cc, '0', n * sizeof *cc), cc[n] = 0;
if (subtask == 1) {
for (i = 0; i < n; i++)
if (query(i, i + 1))
cc[i] = '1';
} else {
l = 0;
while (l < n) {
r = min(l + m, n);
if (!query(l, r)) {
l = r;
continue;
}
lower = l, upper = r;
while (upper - lower > 1) {
i = (lower + upper) / 2;
if (query(l, i))
upper = i;
else
lower = i;
}
cc[lower] = '1', l = lower + 1;
}
}
printf("A %s\n", cc), fflush(stdout);
scanf("%*s");
}
return 0;
}
Compilation message (stderr)
Main.c: In function 'query':
Main.c:21:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%s", s);
| ^~~~~~~~~~~~~~
Main.c: In function 'main':
Main.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d%lf%d", &n, &p, &t), m = 1 / p * 2, subtask = t == 1 ? 1 : 2;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%*s");
| ^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |