Submission #1060777

#TimeUsernameProblemLanguageResultExecution timeMemory
1060777AlidCOVID tests (CEOI24_covid)C++17
100 / 100
1706 ms14416 KiB
#include <vector> #include <queue> #include <math.h> #include <stdio.h> #include <algorithm> #include <string> using namespace std; bool test_pupils(vector<int>) ; const int NMAX = 1123; const int PMAX = 1123; int opt_ask[NMAX][PMAX]; double opt_val[NMAX][PMAX]; double powp[NMAX]; int permutate[NMAX]; void calc(int n, double p) { powp[0] = 1; for(int i=1;i<=n;i++) powp[i]=powp[i-1]*(1-p); opt_val[0][0] = 0; for(int len=1;len<=n;len++) { opt_val[len][1] = opt_val[len-1][0]; for(int prefix=2; prefix<=len; prefix++) { opt_val[len][prefix] = NMAX; for(int test_len=1;test_len<prefix;test_len++) { double pr = 1-powp[test_len]; pr /= 1-powp[prefix]; double v = 1 + pr * opt_val[len][test_len] + (1-pr) * opt_val[len-test_len][prefix-test_len]; if(v < opt_val[len][prefix]) { opt_ask[len][prefix] = test_len; opt_val[len][prefix] = v; } } } opt_val[len][0] = NMAX; for(int test_len=1;test_len<=len;test_len++) { double pr = 1-pow(1-p, test_len); double v = 1 + pr * opt_val[len][test_len] + (1-pr) * opt_val[len-test_len][0]; if(v < opt_val[len][0]) { opt_ask[len][0] = test_len; opt_val[len][0] = v; } } } fprintf(stderr, "Except: %lf\n", opt_val[n][0]); fprintf(stderr, "p = %lf\n", p); } bool calc_done; vector<int> test(int n, double p) { for(int i=0;i<n;i++) permutate[i]=i; srand(4); random_shuffle(permutate, permutate+n); if(!calc_done) calc(n,p); calc_done = true; vector<int> ans; for(int start = 0, prefix=0; start<n;) { int len = n - start; if(prefix == 1) { ans.push_back(permutate[start]); prefix = 0; start++; } else { vector<int> ask; int test_len = opt_ask[len][prefix]; for(int i=0;i<test_len;i++) ask.push_back(permutate[i+start]); if(test_pupils(ask)) { prefix = test_len; } else { if(prefix) prefix -= test_len; start += test_len; } } } return ans; } int n; bool test_pupils(vector<int> pupils) { string out(n, '0'); for(int it : pupils) out[it]='1'; printf("Q %s\n", out.c_str()); fflush(stdout); char in; scanf(" %c", &in); return in=='P'; } int main() { double p; int t; scanf("%d%lf%d", &n, &p, &t); for(int ti=0; ti<t; ti++) { auto positive = test(n, p); { string out(n, '0'); for(int it : positive) out[it]='1'; printf("A %s\n", out.c_str()); fflush(stdout); char in; scanf(" %c", &in); if(in != 'C') return 0; } } return 0; }

Compilation message (stderr)

Main.cpp: In function 'bool test_pupils(std::vector<int>)':
Main.cpp:109:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |  scanf(" %c", &in);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:117:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |  scanf("%d%lf%d", &n, &p, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:128:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |    scanf(" %c", &in);
      |    ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...