QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528576 | #9162. COVID tests | Dimash# | 27.45 | 945ms | 4104kb | C++23 | 3.3kb | 2024-08-23 16:25:42 | 2024-08-23 16:25:43 |
Judging History
answer
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;;
/// You may use:
string s;
// The number of students
int N;
// The probability any given student is positive
double P;
// This function performs a test on a subset of samples.
// Its argument is a vector of Booleans of length N,
// where the i-th element is true if the i-th sample should be added to the mix.
// It returns true if (and only if) at least one of the samples in the mix is positive.
bool loc = 0;
bool test_students(std::vector<bool> mask) {
if(loc) {
bool ans = false;
for(int i = 0; i < N; i++) {
if(mask[i] && s[i] == '1') {
ans = 1;
}
}
return ans;
}
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';
}
/// You should implement:
// This function will be called once for each test instance.
// It should use test_students to determine which samples are positive.
// It must return a vector of Booleans of length N,
// where the i-th element is true if and only if the i-th sample is positive.
vector<int> ord;
bool as(int l,int r) {
vector<bool> ask(N,0);
for(int i = l;i <= min(N - 1,r);i++) {
ask[ord[i]] = 1;
}
return test_students(ask);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(12321);
std::vector<bool> find_positive() {
vector<bool> answer(N),ask(N,0);
ord.resize(N);
iota(ord.begin(),ord.end(),0);
shuffle(ord.begin(),ord.end(),rng);
int col = 0;
function<void(int,int)>go = [&](int l,int r) {
if(l > r) return;
if(l == r) {
col++;
answer[ord[l]] = 1;
return;
}
int mid = (l + r) >> 1;
if(as(l,mid)) {
go(l,mid);
}
if(col < 250 && as(mid+1,r)) {
go(mid+1,r);
}
};
if(P > 0.028545) go(0,N-1);
else {
int i = 0;
while(i < N) {
int l = i - 1,r = N;
while(r - l > 1) {
int mid = (l + r) >> 1;
if(as(i,mid)) {
r = mid;
} else {
l = mid;
}
}
if(r < N) {
answer[ord[r]] = 1;
i = r + 1;
} else {
break;
}
}
}
return answer;
}
int main() {
int T;
scanf("%d %lf %d", &N, &P, &T);
if(loc) cin >> s;
// You may perform any extra initialization here.
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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3936kb
input:
1000 0.789673 1 P P P P P P P P P P P P N P P P P P P P P P P P P P P P N P P P P N P P P P P P P P P P P P N P P P P P P P P P P P P P P N P P P P P P P P N P P P N P P P P P P P P P P P P P P P P P P P P P N P P P P P P P P N P P P P P N P P P P P P P N P P P P P P P P P P P P P P P P N P P P P P ...
output:
Q 1101101111000111101101000001011001100111111100101000110111000110001001001000100101100011100110101101101110001101101000001010100010000010111011001010100011100111011110000010010111111010100011111000001110111000001001110011101110100011100011110111100100101100011000101100101000001101011110000110011000...
result:
points 0.0 0.0 translate:wrong
Subtask #2:
score: 27.45
Acceptable Answer
Test #18:
score: 49.42
Acceptable Answer
time: 28ms
memory: 3876kb
input:
1000 0.001 300 N N N N N N N N N N C N P N N N N P P P P N N N N N N N N N C P P N N P P N P P P N P P P N N P P N N P N N P P P P N N N N N N N N N C N N N N N N N N N N C N N N N N N N N N N C P P P N N N N N P P N N N N N N N N N N C N N P N P N N P P P N N N N N N N N C N N N N N N N N N N C N N...
output:
Q 0000011111110100101110111111001000101100010000011010110100111011100100001011110101001000100001011111101001011101010010000111110000100010001001010000010000011001101110011111010010001101100011010101000111110100111000100100001011010111111101010000000000010010010110111010111010010001101110000110100001...
result:
points 0.54911111110 0.5491111111 Output is correct (P=0.001, F=15.1, Q=18.2) -> 49.42 points
Test #19:
score: 74.78
Acceptable Answer
time: 55ms
memory: 3976kb
input:
1000 0.005256 300 P P P P P P N N P P P P N P N P P N P N P P N N N P N P N N N P N N P N N N N P N N P N P P N N N N N N N C P P P P P P N P N P P N P N N P N P P P N P P N P N P N P N N N N N N N N N C P P P P N N P N P P N N N N N N N N N N C P P P P N N P N P P N P P P P N P N P P P P P P N N P ...
output:
Q 1001101100110000010101111100001110001100110110100011011111101110110111110011010101100000010100011011010010110001111010110110010011011000010000000001000110110000010001000101101001000100011110000000101111010001100010101001010100010000100100110101011101110110000010011111111000001111001000010111010110...
result:
points 0.83088888890 0.8308888889 Output is correct (P=0.005256, F=51.1, Q=53.7) -> 74.78 points
Test #20:
score: 57.67
Acceptable Answer
time: 79ms
memory: 3908kb
input:
1000 0.011546 300 P P P N P N P N N N P P P P P N N P P P P P P P P N N P N P P P P P N N P P P P P P P P N N N P P P P P N P P P N P P N P P N N N N P P P P P P N N N P N P N P P N N N P N P P N N P N N N N P P N N P N N N N N P N N N P N N N N N N N N C P N N N N P P N N N P N N P N P P N P P P N ...
output:
Q 1011101010111000011010000000110100101010011111001111100111000010000001010111110001001111100110110101100111011100000011111010111011101111001111010100101101001000011010101011000100111000000001001110010000100101100110010000010000101001001100100011100111001000111111011101010001101011110001010111011000...
result:
points 0.64077777780 0.6407777778 Output is correct (P=0.011546, F=94.9, Q=108.2) -> 57.67 points
Test #21:
score: 38.9
Acceptable Answer
time: 195ms
memory: 4052kb
input:
1000 0.028545 300 P P P P N P N P P N P P P P N N N P N P P P P N N N P P P P P P P P N N P N N P P P P P N P N N P P P P P P P P N N N P P P P N P N P N N P P N N P P N P N N P P P P N N N P P P P P N P P N P N P P P P P P N P P P P P N P P P N P P P P P P N P N N P P P P P N P N P P P P P N P N N ...
output:
Q 0111010100011110111011000001011010010011110000100100101000100011011111111010111101111000101100000011011001111011001101001110111010110001101110010110111110111111110100001111011101101110010101000001011101001111110110001100110111111100110011100101001101110111110011000010110111010101110000110111000011...
result:
points 0.43222222220 0.4322222222 Output is correct (P=0.028545, F=191.5, Q=254.4) -> 38.90 points
Test #22:
score: 27.45
Acceptable Answer
time: 344ms
memory: 4104kb
input:
1000 0.039856 300 P P P N P P N P P N P P N P N N N P N P P P P N P N P N P N P P P N P P N N N P P N P N P N P N P N P P P P N P P N P N P P N P N P N P P N P P N P P P N P N N P N P P P P N N N P P P P N P N P N P P P P N P N N P P P N P P N N N N P P P N P P P P N P N P P P N N N P P P P N P N P ...
output:
Q 1101101011101110011110101001111011010110010110011110000111110110010001111000100010011000011110111001011111101011100110101100010110010010000111011111011100111000010011000001101101111100100011000010011100100110001100000011100000000000100100000111110000001001101110001010100101011101000011111001011000...
result:
points 0.3050 0.305 Output is correct (P=0.039856, F=246.3, Q=386.6) -> 27.45 points
Test #23:
score: 28.01
Acceptable Answer
time: 502ms
memory: 4104kb
input:
1000 0.068648 300 P P P P P P P N P N P N P P P P P N N N N P P P N P P N P N N P P P N P P N N N P P P P N P P P N P N P P N P N P P N P N P N P N P P P P P P P N N N N P P N P P N P N N P P P P P P P N P N N N P P P P N P N N N P P N P P N P N P P N P P N P N P N P P P N N P P P P N P N P P N N N ...
output:
Q 1111011100111011100111101110011000000110010101111100111101111110011000111011100101111000001011110000010111101110101111010000100011101000010111111000110001011110111111110111101001000110001101001100001100101110111110111000011000000100010000011000110110110111111000001001101100100111111011101000110110...
result:
points 0.31122222220 0.3112222222 Output is correct (P=0.068648, F=366.2, Q=568.8) -> 28.01 points
Test #24:
score: 28.84
Acceptable Answer
time: 538ms
memory: 3876kb
input:
1000 0.104571 300 P P P P P P P P P P N P P N P P N P N N P P P P P N P N P P P N P N N P P N P P P N P N N P P P N P N P P N P P N N P P P P N P N P N P N P P P N P P N N P P P P N P N P N P P P P P P N N N P N P N P P N N P P P P P N P N P P N P N P P N P N P N P N P P P N P P N P P N P P N P P N ...
output:
Q 1101001010111111011000100010001101001000100101110011000011110010101111001111101100110111110101010010001100010011010000111000100100110011011010001101110101101010100010100111110010111111100110011111111010100001001110111111110011000101000010101111000111101100100000010110010101110111001011100001110001...
result:
points 0.32044444440 0.3204444444 Output is correct (P=0.104571, F=490.3, Q=750.3) -> 28.84 points
Test #25:
score: 29.34
Acceptable Answer
time: 743ms
memory: 3932kb
input:
1000 0.158765 300 P P P P P P P P N P P P N P N P P N P N N P P P P N P N P N P P P N P N N P P P P N P N P P N P N P P N P N P N P P P P N P N P P N P P P P N N P P N P P N P P P P N P N P P N P N P P P N P P N N P P P N P N P P P P P P P N N N P P P P N P N P N P P N N P P P P N P P P N P N N N P ...
output:
Q 0001001101010010001011100010001011111000101101110111011100000111001110010010101011010011001110100010110110011000000010011011001111001000010011000011100011110111001001001110111100101110101001101111001011001100111111101010100110000011011000001110010110101110101000111001111110110111010011111011010100...
result:
points 0.3260 0.326 Output is correct (P=0.158765, F=639.1, Q=969.5) -> 29.34 points
Test #26:
score: 29.21
Acceptable Answer
time: 945ms
memory: 3876kb
input:
1000 0.2 300 P P P P P P P P N P N P N P P N P N P P P P N P N P P P P P P N N P N P N P P P P N P N P P P N N P P P P P P N N N N P P N P P N P P P N P P P N P N P P P N N P P P P P P P N N N P P N P N P P P N P N P P P N P P N P P N P P P N N P P P N P N P P N P P N P P N P P N P N P P N P N P N P...
output:
Q 0010011000101010100111111011010100011100010011000110111000001001000111001100010101011010001011000000110101000010101000110111001011111001101101011001000110101110001110110101010101111001000000110111011100000111000011100011101011010010111100101000111101101010111111000001000011010100011010011110110111...
result:
points 0.32455555560 0.3245555556 Output is correct (P=0.2, F=731.4, Q=1112.0) -> 29.21 points