Submission #1199462

#TimeUsernameProblemLanguageResultExecution timeMemory
1199462lightonCOVID tests (CEOI24_covid)C++20
53.65 / 100
1152 ms676 KiB
#include <cassert> #include <cstdio> #include <string> #include <vector> #include<bits/stdc++.h> #define pb push_back #define all(v) v.begin(),v.end() #define forf(i,s,e) for(int i = s; i<=e; i++) #define forb(i,s,e) for(int i = s; i>=e; i--) #define idx(i,v) lower_bound(all(v),i)-v.begin() #define comp(v) v.erase(unique(all(v)),v.end()) #define sz(v) (int)v.size() #define fs first #define se second #define SP << " " << #define LN << "\n" #define IO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false); using namespace std; /// You may use: // 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 test_students(std::vector<bool> mask) { 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. double a[1001]; pair<double,int> dp[1001][2]; vector<bool> answer,v; void findn(){ a[0] = 1; forf(i,1,N) a[i] = a[i-1]*(1-P); dp[1][1] = {0,0}; dp[1][0] = {1,1}; forf(i,2,N){ dp[i][1] = {1e18,0}; dp[i][0] = {1e18,0}; forf(j,1,i-1){ double p = ((double)j)/i; double e = 1 + p*(dp[j][1].fs + dp[i-j][0].fs) + (1-p)*(dp[i-j][1].fs); dp[i][1] = min(dp[i][1], {e,j}); } forf(j,1,i){ double e = 1+(1-a[j])*(dp[j][1].fs + dp[i-j][0].fs) + a[j]*dp[i-j][0].fs; dp[i][0] = min(dp[i][0], {e,j}); } } } void go(vector<int> c, int d){ if(sz(c) == 1 && d == 1) { answer[c[0]] = 1; return; } if(sz(c) == 0) return; random_shuffle(all(c)); int n = sz(c); int m = dp[n][d].se; vector<int> nc1,nc2; forf(i,0,m-1) nc1.pb(c[i]); forf(i,m,n-1) nc2.pb(c[i]); for(auto i : nc1) v[i] = 1; int f = test_students(v); for(auto i : nc1) v[i] = 0; if(f){ go(nc1, 1); go(nc2,0); } else{ go(nc2,d); } } std::vector<bool> find_positive() { //cout<<dp[N][0].fs; forf(i,0,N-1) answer[i] = 0; vector<int> c; forf(i,0,N-1) c.push_back(i); go(c,0); return answer; } int main() { int T; scanf("%d %lf %d", &N, &P, &T); // You may perform any extra initialization here. answer.resize(N,0); v.resize(N,0); findn(); 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; }

Compilation message (stderr)

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