Submission #1058860

#TimeUsernameProblemLanguageResultExecution timeMemory
1058860rainboyCOVID tests (CEOI24_covid)C11
100 / 100
1323 ms11860 KiB
#include <stdio.h> #include <string.h> #define N 1000 #define INF 1e9 double min(double a, double 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'; } double qq[N + 1], dp[N + 1], dq[N + 1][N + 1]; int ll[N + 1], mm[N + 1][N + 1]; void init() { int i, l, r, m; double x; qq[0] = 1; for (i = 1; i <= n; i++) qq[i] = qq[i - 1] * (1 - p); dp[0] = 0; for (r = 1; r <= n; r++) { dp[r] = INF; for (l = r - 1; l >= 0 && l >= r - n / 2; l--) { if (r - l == 1) dq[l][r] = dp[l]; else { dq[l][r] = INF; for (m = r - 1; m > l; m--) { x = (dq[l][m] * qq[r - m] * (1 - qq[m - l]) + dq[m][r] * (1 - qq[r - l] - qq[r - m] * (1 - qq[m - l]))) / (1 - qq[r - l]) + 1; if (dq[l][r] > x) dq[l][r] = x, mm[l][r] = m; } } x = dp[l] * qq[r - l] + dq[l][r] * (1 - qq[r - l]) + 1; if (dp[r] > x) dp[r] = x, ll[r] = l; } } } char cc[N + 1]; void solve(int r); void solve_(int l, int r) { if (r - l == 1) cc[l] = '1', solve(l); else if (query(mm[l][r], r)) solve_(mm[l][r], r); else solve_(l, mm[l][r]); } void solve(int r) { if (r == 0) return; else if (query(ll[r], r)) solve_(ll[r], r); else solve(ll[r]); } int main() { int t, subtask; scanf("%d%lf%d", &n, &p, &t), m = 1 / p * 4, subtask = t == 1 ? 1 : 2, init(); while (t--) { int i; 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 solve(n); printf("A %s\n", cc), fflush(stdout); scanf("%*s"); } return 0; }

Compilation message (stderr)

Main.c: In function 'query':
Main.c:22:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%s", s);
      |  ^~~~~~~~~~~~~~
Main.c: In function 'main':
Main.c:81:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |  scanf("%d%lf%d", &n, &p, &t), m = 1 / p * 4, subtask = t == 1 ? 1 : 2, init();
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:93:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   scanf("%*s");
      |   ^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...