Submission #1077615

#TimeUsernameProblemLanguageResultExecution timeMemory
1077615ArturgoCOVID tests (CEOI24_covid)C++14
100 / 100
3409 ms8500 KiB
#include <bits/stdc++.h> using namespace std; bool test_students(vector<bool> mask); double esp(int prefix, int total); int N; double P; bool estPasse[1001][1001]; double dp[1001][1001]; double powers[1001]; pair<double, int> opt_no_prefix(int total) { double min_esp = INFINITY; int opt_sz = -1; for(int sz = 1;sz <= total;sz++) { double P_vide = powers[sz]; double E = 1 + esp(0, total - sz) * P_vide + esp(sz, total) * (1 - P_vide); if(E < min_esp) { min_esp = E; opt_sz = sz; } } return {min_esp, opt_sz}; } pair<double, int> opt_prefix(int prefix, int total) { double min_esp = INFINITY; int opt_sz = -1; for(int sz = 1;sz < prefix;sz++) { double P_vide = powers[sz] * (1 - powers[prefix - sz]) / (1 - powers[prefix]); double E = 1 + esp(prefix - sz, total - sz) * P_vide + esp(sz, total) * (1 - P_vide); if(E < min_esp) { min_esp = E; opt_sz = sz; } } return {min_esp, opt_sz}; } double esp(int prefix, int total) { if(estPasse[prefix][total]) return dp[prefix][total]; estPasse[prefix][total] = true; double& answer = dp[prefix][total]; if(total == 0) return answer = 0; if(prefix == 0) return answer = opt_no_prefix(total).first; if(prefix == 1) return answer = esp(0, total - 1); return answer = opt_prefix(prefix, total).first; } bool ask_inter(int deb, int fin) { vector<bool> mask(N, false); fill(mask.begin() + deb, mask.begin() + fin, true); return test_students(mask); } vector<bool> find_positive() { vector<bool> answer(N, false); int prefix = 0, total = N; while(total != 0) { if(prefix == 0) { int opt_sz = opt_no_prefix(total).second; if(ask_inter(N - total, N - total + opt_sz)) { prefix = opt_sz; } else total -= opt_sz; } else if(prefix == 1) { answer[N - total] = true; prefix = 0; total -= 1; } else { int opt_sz = opt_prefix(prefix, total).second; if(ask_inter(N - total, N - total + opt_sz)) prefix = opt_sz; else { prefix -= opt_sz; total -= opt_sz; } } } return answer; } void init() { powers[0] = 1.; for(int i = 1;i <= 1000;i++) { powers[i] = (1 - P) * powers[i - 1]; } } int main() { int T; scanf("%d %lf %d", &N, &P, &T); init(); for (int i = 0; i < T; i++) { vector<bool> answer = find_positive(); assert(answer.size() == (size_t)N); 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; } bool test_students(vector<bool> mask) { assert(mask.size() == (size_t)N); 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'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:118:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:137:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...