QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#492107 | #9162. COVID tests | nhuang685 | 100 ✓ | 495ms | 15824kb | C++20 | 3.3kb | 2024-07-26 09:26:58 | 2024-07-26 09:26:59 |
Judging History
answer
/**
* @author n685
* @brief
* @date 2024-07-25 19:53:13
*
*
*/
#include <bits/stdc++.h>
#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbgP(...) 420
#define dbgRP(...) 420420
void nline() {}
void bar() {}
#endif
using db = double; // change it to double as needed
// [[maybe_unused]] const db PI = std::acos(static_cast<db>(-1.0));
[[maybe_unused]] constexpr db PI = std::numbers::pi_v<db>;
constexpr db EPS = 1e-9;
template <class T, class U> constexpr bool eq(const T &a, const U &b) {
if constexpr (std::is_floating_point_v<std::common_type_t<T, U>>) {
return std::abs(a - b) < EPS;
} else {
return a == b;
}
}
constexpr int MX = 1000;
std::array<std::array<db, MX + 1>, MX + 1> dp;
std::array<std::array<int, MX + 1>, MX + 1> len;
std::array<db, MX + 1> ppow, ippow;
int n;
bool query(int l, int r) {
std::string q(n, '0');
for (int i = l - 1; i <= r - 1; ++i) {
q[i] = '1';
}
std::printf("Q %s\n", q.c_str());
std::fflush(stdout);
char c;
std::scanf(" %c", &c);
return c == 'P';
}
int main() {
db p;
int t;
// std::cin >> n >> p >> t;
std::scanf("%d %lf %d", &n, &p, &t);
if (eq(p, 0)) {
for (int i = 0; i < t; ++i) {
std::printf("A ");
for (int j = 0; j < n; ++j) {
std::printf("0");
}
std::printf("\n");
std::fflush(stdout);
}
return 0;
}
if (eq(p, 1)) {
for (int i = 0; i < t; ++i) {
std::printf("A ");
for (int j = 0; j < n; ++j) {
std::printf("1");
}
std::printf("\n");
std::fflush(stdout);
}
return 0;
}
ppow[0] = 1;
for (int i = 1; i <= n; ++i) {
ppow[i] = ppow[i - 1] * (1 - p);
}
for (int i = 1; i <= n; ++i) {
ippow[i] = 1 / (1 - ppow[i]);
}
// std::vector dp(n + 1,
// std::vector(n + 1, std::numeric_limits<db>::infinity()));
db inf = std::numeric_limits<db>::infinity();
dp[0][0] = 0;
for (int suf = 1; suf <= n; ++suf) {
dp[suf][1] = dp[suf - 1][0];
for (int pre = 2; pre <= suf; ++pre) {
dp[suf][pre] = inf;
for (int j = 1; j < pre; ++j) {
db pv = (ppow[j] - ppow[pre]) * ippow[pre];
db val = pv * dp[suf - j][pre - j] + (1 - pv) * dp[suf][j] + 1;
if (dp[suf][pre] > val) {
dp[suf][pre] = val;
len[suf][pre] = j;
}
}
}
// pre = 0
dp[suf][0] = inf;
for (int j = 1; j <= suf; ++j) {
db pv = ppow[j];
db val = pv * dp[suf - j][0] + (1 - pv) * dp[suf][j] + 1;
if (dp[suf][0] > val) {
dp[suf][0] = val;
len[suf][0] = j;
}
}
}
while ((t--) != 0) {
std::string ans(n, '0');
int suf = n, pre = 0;
while (suf > 0) {
// dbg(suf, pre, dp[suf][pre]);
if (pre == 1) {
ans[n - suf] = '1';
--suf;
pre = 0;
} else {
int j = len[suf][pre];
if (query(n - suf + 1, n - suf + j)) {
pre = j;
} else {
if (pre > 0) {
pre -= j;
}
suf -= j;
}
}
}
std::printf("A %s\n", ans.c_str());
std::fflush(stdout);
char c;
std::scanf(" %c", &c);
if (c == 'W') {
return 0;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 457ms
memory: 15676kb
input:
1000 0.789673 1 P N P P P P P P N P P N P N P P P P P N P P P P P P N P P P P P P P P P P P P P P P P P P N N N P P P P N P P P P N N P P P N P P P P N P P P P P N N P N P P P P P N P P P P P P P P P P P P P P P P P P N N P N P P P P P P P P N P N P P P N N P P P P P P P P P P P P P P P P P P P P N ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #2:
score: 10
Accepted
time: 383ms
memory: 15568kb
input:
1000 0.686378 1 N P N N N P N N P N P P N N P P P P N P P P N P P P N N P N P P P N N N P N P P P N P P P P P P N N P P P N P P P P P P P P P P P P P P P P P P N N P P N N N P P N P N P P P P P N P N N P P P N P N N P N P P P P N P N P P P P N P P N P P P N P N P P N P N N P P N P N P P N N P N N P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #3:
score: 10
Accepted
time: 476ms
memory: 15612kb
input:
1000 0.873862 1 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 P P P P P P P N P P P P P P P P P N P P P P P P P P P P P P P N P P P P P P P P P N P P P N P P N P P P P P P N P P 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 P P P P P P P P P P P P N P P P P P N P P N P P P P P P P P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #4:
score: 10
Accepted
time: 360ms
memory: 15476kb
input:
1000 0.669578 1 P P N P P P P P N P N P P P N P P P P P P P N P P P P N N P N P N P P N P P N P P N P N P P P P P P P P P P P P P N N P P N P P N N P P N N P N P N P N P P N N P P P P P P P P P P N P P N P P N P P P P P P N P P P P N N N P N P P N P P N N P P N P P P N P P N P P P P P N P P N P P P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #5:
score: 10
Accepted
time: 481ms
memory: 15608kb
input:
1000 0.907052 1 P P P P 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 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 P P P P P P P P N P P P P P N 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 P P P P P P P P P P P P P P P P P N P P P N P P P P N N P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #6:
score: 10
Accepted
time: 495ms
memory: 15528kb
input:
1000 0.844418 1 P P P P P P P P P P P P N P P P 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 P P P P P P P P P P P P P N P P P P P N P P P N P P P P P N P P P P P P N P P P N P N P P N P P P N P P N P P P N N N P P P P N N P N N P P P P P P P N P N P P P P N P P P P P P P P P P P P P P P P P P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #7:
score: 10
Accepted
time: 234ms
memory: 15524kb
input:
1000 0.533576 1 P P P N N N N P P N N P N P N P P N P N N P N P N P P N P N P N P P P P N N N P P P P P N N P P N P P P P P N P P P P N N N N N P N P P P N P N P P P N P P P P N P N P P N N P N N P N P P N N P N P P N N P N N P N N P P N N N N P N P N N P N N P P N P P P P P N N N P P N P N P N P P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #8:
score: 10
Accepted
time: 241ms
memory: 15516kb
input:
1000 0.415944 1 N N N N N N N P N N P N N P N P N N N P N N N N N N N N N P N N N N P P P P N P N N P N N P N N P P N P P P N N P N P N N N N N P N P N P N P N N N P N N N N P N N P P P P P N N N P P N N N P N N P N P P P N P P N P P P N P N P P P P P N N N P P P P P P P P N N N P P N N N N N N P P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #9:
score: 10
Accepted
time: 287ms
memory: 15524kb
input:
1000 0.596017 1 P N P P N N P N N P P P N P N N P P P N P N P N N N P N N P N N P N P P P N P P N P P P N P N P P P N P N N P P P N P N N N P N N N P P P N P P P N N P N N P P N N P N P N N P N N P N P P N N P P P P N P P P N N P P P P P P N P P P N P P N P P P P P P P P N P P P P N N P P P N P N P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #10:
score: 10
Accepted
time: 230ms
memory: 15776kb
input:
1000 0.157686 1 N N N P P N P N N P P P P N P N P P P N N P N N P N N P P P P N P P P N N P P N N N N N P N P N N N P N N P P P N P N N P P P N N P P N P P P P P P P P P N N N N P N P P N P N P P N N P P N N P N N N N N P P P N P P N P P N N P N P P N P N N N P N P N N N P P N N P P N P P N N N N P ...
output:
Q 1111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #11:
score: 10
Accepted
time: 218ms
memory: 15516kb
input:
1000 0.380215 1 N P N N P N N P P N P N P P P N N P N P P P P P N P P N P N N P N N P N P P P P P P N N P N P P N N N N N N N P P P P N N P P P P N P N N N P N P N N P P N N P P N N P P P P P P P P P P P P P P N N N N N P P N P P N P N N N N N P N P N P N N P P P P N P P P P N N P P P P N N P N P N ...
output:
Q 1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #12:
score: 10
Accepted
time: 228ms
memory: 15548kb
input:
1000 0.432565 1 P N P N N P N N N P P P N P P N N N N N N N N N P P P N P P N N P P P P N P P N N N N P P P P N P N N P P P N N N N P N P N P N P N P P N N P N N P N N N P N P N N N P N N P N P N N N P N N P P P P P P N P N N N N N N N P P N P N N N N P P P N P N N P P P N P P P P P P N P N P P N P ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #13:
score: 10
Accepted
time: 239ms
memory: 15540kb
input:
1000 0.509199 1 P P N P N N N P P N N N N N P N N P P N P P N P P P P P N N P N P P N P P P P P P P P P P N P P P N N P N P P N P N P N N P N P N P N N N N N P P N N N P P P N N P P P P N N N N P P N P N N N P P P P P N N N P P N P P N P N P P P N N P P N N N N N N P P P N N P P N N N N N N P P N N ...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #14:
score: 10
Accepted
time: 220ms
memory: 15820kb
input:
1000 0.381646 1 N P N N N P P P P P P N N P N N P N P N P N P N N N N P N P P N N P P P P N N P N N N P P P N N N P P P P P P P N P P P N P P P P P N P N P P P P N N P N N P P P P P N P P P N P P N N P P P P N P P N N P N N P P P P N N P N P P P N N P P N P N P P N P P N N P P P P N N P N P P P P N ...
output:
Q 1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #15:
score: 10
Accepted
time: 236ms
memory: 15572kb
input:
1000 0.42815 1 N P P N P N P P P N N P N N P N N P P P N N N N P P P N N N P P N P N N P N N N P P N N N N P N N P P N P N N N N P N N N N N P N P P N P P P P N N N P P P N P P P N P P N P N N N P N N P N N P P N P P N N P N N P P P P P P P N N N P N P N P N N N N N N N P N N N P N P P P P N N N P N...
output:
Q 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Test #16:
score: 10
Accepted
time: 1ms
memory: 3864kb
input:
1000 1 1 C
output:
A 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
points 1.0 1.0 translate:success
Test #17:
score: 10
Accepted
time: 0ms
memory: 3916kb
input:
1000 0 1 C
output:
A 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 translate:success
Subtask #2:
score: 90
Accepted
Test #18:
score: 90
Accepted
time: 244ms
memory: 15648kb
input:
1000 0.001 300 N N C N P P N N P P N N P P N C N P N P N P N N P P P P P N P P N P N P P P N N N P N N C N N C N N C P N P N P N P P N N N C N P N P P N P P N P P N C N N C N N C P N P P P P P N P P N C N N C N P N P N P N P N N P P N P P P P N N N C N P P N P N P P P P N P P N P P P N P P P N P P P...
output:
Q 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
points 1.0 1.0 Output is correct (P=0.001, F=15.1, Q=10.8) -> 90.00 points
Test #19:
score: 90
Accepted
time: 251ms
memory: 15524kb
input:
1000 0.005256 300 P N P N N N P N P P P P N P P N N N P N P P N N P N N N P N P P P P N N N P N P N P N P P N C N N N N P N P N P N P P N P N N N P N P P P P N N P N P N N C N N N N N N N P P N N P P P P N C N P P P N P N N P N P P P P N N N P P P P P P N P N N N N P P N N P N P N N P N P N N P N N ...
output:
Q 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.005256, F=51.1, Q=46.3) -> 90.00 points
Test #20:
score: 90
Accepted
time: 313ms
memory: 15824kb
input:
1000 0.011546 300 P P N P N P P P P P N N P P N N N P N P P N P N N P P P P N N P P P P P N P P P P P N P P N N N N N P P P N P N N N N N N N N N P N N P P P N P N P N N N P N P P P N N N P P N P P P P P N C N P N P N P P N N N N N P P N N P N P N N N N N N N P N P P N P P N N P P P P N P N N C P P ...
output:
Q 1111111111111111111111111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.011546, F=94.9, Q=90.5) -> 90.00 points
Test #21:
score: 90
Accepted
time: 342ms
memory: 15620kb
input:
1000 0.028545 300 P P P P P N N N P P N N P N N P P N N N P P P N N N N P N N N N P P P P N N N P P P P N N N N P N N N N N P N N N P P P N P N N P P N P N P P P N N N P N P P P P P P P N N P P P N P P N P N N N P N N N P N N P N N N P N N N P N P N P N P P P N N P N N N N P N N N P P N N P N P N P ...
output:
Q 1111111111111111111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.028545, F=191.5, Q=187.7) -> 90.00 points
Test #22:
score: 90
Accepted
time: 396ms
memory: 15660kb
input:
1000 0.039856 300 P N P P N N P P P N P P P P N N N N N N N N N P P N P P N P N P P P P P P P N P P N P N P P N N P P P N N N P P P N N N N P P N P N P N N N N P P N N N N N P N N N N N N P P N P N N N N N N N P N P N P N P N P N P N P N N N N N N P N P P P N P N N P N N P P P P P P P P P P P P P N ...
output:
Q 1111111111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.039856, F=246.3, Q=243.7) -> 90.00 points
Test #23:
score: 90
Accepted
time: 438ms
memory: 15780kb
input:
1000 0.068648 300 N P N P P P P N N P P N N P P P P N P P P N P P P P P P P N P N N N P P N P P N N P P N P P N N N P P N N N P N N P N P N N N P P P N N N N N N N P N N N N P N N N P P P P P P P P P N P P N N N P N N N N N P P P N N N P N N P P P N N N P N N N P P P N P N P N P N P N N N P N P N P ...
output:
Q 1111111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.068648, F=366.2, Q=364.2) -> 90.00 points
Test #24:
score: 90
Accepted
time: 371ms
memory: 15528kb
input:
1000 0.104571 300 N N N P N P N N N P P P P P N P P P N N N P N P P P N P P P N N N P N P P N P P P P N P P P P P N P P P P P N N N N N N P N P N N N P N P N N N P N N P N N N N P N N P P P N P N P N P N P P P N P N N P N N P N P N N P N N P N N P P N P P P P P P N N P P N N N P N P N N P N P P N P ...
output:
Q 1111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.104571, F=490.3, Q=488.2) -> 90.00 points
Test #25:
score: 90
Accepted
time: 462ms
memory: 15612kb
input:
1000 0.158765 300 N N N N P P P N P P N N N P P N P P P N N N N N N N N P N N P P N N N N N P P N N N N P P N N N N P N N N P N N N N P N P N N N P N P P N P N P P P N P N P N N N N N N P P P P P P P P P N N P P N N N N N N P N N N N P P N P N P P P P P P N P N N N P N P P N N P N P N P P N P N P N ...
output:
Q 1111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.158765, F=639.1, Q=633.1) -> 90.00 points
Test #26:
score: 90
Accepted
time: 479ms
memory: 15772kb
input:
1000 0.2 300 N P N P N P N P P N P N N N N N P N N P N P P P N P N P P N P P N N P N P N P P P N P N P P P P N P N N P N N N N N N P N N P P P P N P N N N P N N N P P N P P N N N N P N P P N P P P P N N N N P P P P P N P P N N N P N N P N P P N P N N N N P N P P P P P P N N N N P N P N N N P N P N N...
output:
Q 1110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
points 1.0 1.0 Output is correct (P=0.2, F=731.4, Q=729.3) -> 90.00 points
Extra Test:
score: 0
Extra Test Passed