Submission #1199498

#TimeUsernameProblemLanguageResultExecution timeMemory
1199498lightonCOVID tests (CEOI24_covid)C++20
100 / 100
1152 ms11784 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][1001]; vector<bool> answer,v; void findn(){ a[0] = 1; forf(i,1,N) a[i] = a[i-1]*(1-P); dp[1][0] = {1,1}; dp[1][1] = {0,0}; forf(i,2,N){ forf(j,0,i) dp[i][j] = {1e18,0}; dp[i][1] = {dp[i-1][0].fs,0}; forf(j,2,i){ if(j==1) continue; forf(k,1,j-1){ double p = (1-a[k]) / (1-a[j]); dp[i][j] = min(dp[i][j], {1 + p*dp[i][k].fs + (1-p)*dp[i-k][j-k].fs ,k}); } } forf(k,1,i){ double p = 1-a[k]; dp[i][0] = min(dp[i][0], {1 + p*dp[i][k].fs + (1-p)*dp[i-k][0].fs, -k}); } } } void go(vector<int> c){ random_shuffle(all(c)); int n = N, d = 0; while(n){ int m = dp[n][d].se; if(d==1){ answer[c[0]] = 1, c.erase(c.begin()); n--, d=0; } else if(m>0){ forf(i,0,m-1) v[c[i]] = 1; int f = test_students(v); forf(i,0,m-1) v[c[i]] = 0; if(f) d = m; else{ n -= m , d -= m; c.erase(c.begin(), c.begin()+m); } } else{ m *= -1; forf(i,d,d+m-1) v[c[i]] = 1; int f = test_students(v); forf(i,d,d+m-1) v[c[i]] = 0; if(f){ d += m; } else{ n -= m; c.erase(c.begin()+d, c.begin()+d+m); } } } } 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); 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:128:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:146:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...