Submission #1133761

#TimeUsernameProblemLanguageResultExecution timeMemory
1133761PagodePaivaCOVID tests (CEOI24_covid)C++17
31.25 / 100
3783 ms420 KiB
#include<bits/stdc++.h>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;


int N;
double P;

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';
}

vector <bool> ans;
vector <bool> query;
vector <int> pos;

void solve(int l, int r){
	if(l == r){
		ans[pos[l]] = true;
		return;
	}
	int mid = (l+r)/2;
	for(int i = l;i <= mid;i++){
		query[pos[i]] = true;
	}
	bool res = test_students(query);
	for(int i = l;i <= mid;i++){
		query[pos[i]] = false;
	}
	if(res) solve(l, mid);
	for(int i = mid+1;i <= r;i++){
		query[pos[i]] = true;
	}
	res = test_students(query);
	for(int i = mid+1;i <= r;i++){
		query[pos[i]] = false;
	}
	if(res) solve(mid+1, r);
	return;
}

std::vector<bool> find_positive() {
	ans.clear();
	pos.clear();
	query.clear();
	for(int i = 0;i < N;i++){
		pos.push_back(i);
		ans.push_back(false);
		query.push_back(false);
	}
	random_shuffle(pos.begin(), pos.end());
	if(P == 0) return ans;
	int d = (1.0/P);
	d /= 2;
	//cout << d << endl;
	for(int i = 0;i < N;i += d){
		int r = min(N-1, i+d-1);
		for(int j = i;j <= r;j++){
			query[pos[j]] = true;
		}
		bool res = test_students(query);
		for(int j = i;j <= r;j++){
			query[pos[j]] = false;
		}
		if(res) solve(i, r);
	}
	return ans;
}

int main() {
	srand(time(0));
    int T;
    scanf("%d %lf %d", &N, &P, &T);

    // You may perform any extra initialization here.

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