#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 *ii, int k) {
static char cc[N + 1], s[2];
int h;
memset(cc, '0', n * sizeof *cc);
for (h = 0; h < k; h++)
cc[ii[h]] = '1';
printf("Q %s\n", cc), fflush(stdout);
scanf("%s", s);
return s[0] == 'P';
}
void shuffle(int *ii, int n) {
int h, h_, tmp;
for (h = 0; h < n; h++) {
h_ = rand_() % (h + 1);
tmp = ii[h], ii[h] = ii[h_], ii[h_] = tmp;
}
}
int main() {
int t, subtask;
scanf("%d%lf%d", &n, &p, &t), m = 1 / p, subtask = t == 1 ? 1 : 2;
while (t--) {
static char cc[N + 1];
static int ii[N];
int n_, n__, h, i, l, r, lower, upper;
memset(cc, '0', n * sizeof *cc), cc[n] = 0;
if (subtask == 1) {
for (i = 0; i < n; i++) {
ii[0] = i;
if (query(ii, 1))
cc[i] = '1';
}
} else {
n_ = 0;
for (i = 0; i < n; i++)
ii[n_++] = i;
while (n_ > 0) {
shuffle(ii, n_);
n__ = 0;
for (l = 0; l < n_; l += m) {
r = min(l + m, n_);
if (query(ii + l, r - l)) {
lower = l, upper = r;
while (upper - lower > 1) {
h = (lower + upper) / 2;
if (query(ii + l, h - l))
upper = h;
else
lower = h;
}
cc[ii[lower]] = '1';
for (h = lower + 1; h < r; h++)
ii[n__++] = ii[h];
}
}
n_ = n__;
}
}
printf("A %s\n", cc), fflush(stdout);
scanf("%*s");
}
return 0;
}
Compilation message
Main.c: In function 'query':
Main.c:24:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%s", s);
| ^~~~~~~~~~~~~~
Main.c: In function 'main':
Main.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d%lf%d", &n, &p, &t), m = 1 / p, subtask = t == 1 ? 1 : 2;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:80:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%*s");
| ^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
4 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
5 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
3 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
344 KB |
Output is correct (P=0.001, F=15.1, Q=10.7) -> 90.00 points |
2 |
Correct |
68 ms |
344 KB |
Output is correct (P=0.005256, F=51.1, Q=47.7) -> 90.00 points |
3 |
Correct |
121 ms |
344 KB |
Output is correct (P=0.011546, F=94.9, Q=92.8) -> 90.00 points |
4 |
Correct |
305 ms |
344 KB |
Output is correct (P=0.028545, F=191.5, Q=191.4) -> 90.00 points |
5 |
Correct |
419 ms |
344 KB |
Output is correct (P=0.039856, F=246.3, Q=251.3) -> 83.24 points |
6 |
Correct |
605 ms |
344 KB |
Output is correct (P=0.068648, F=366.2, Q=373.6) -> 83.27 points |
7 |
Correct |
838 ms |
344 KB |
Output is correct (P=0.104571, F=490.3, Q=497.8) -> 84.81 points |
8 |
Correct |
1089 ms |
344 KB |
Output is correct (P=0.158765, F=639.1, Q=656.5) -> 81.16 points |
9 |
Correct |
1216 ms |
344 KB |
Output is correct (P=0.2, F=731.4, Q=754.7) -> 79.83 points |