Submission #1220661

#TimeUsernameProblemLanguageResultExecution timeMemory
1220661MateiKing80COVID tests (CEOI24_covid)C++20
80.19 / 100
752 ms408 KiB
#include <bits/stdc++.h>

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

std::vector<bool> find_positive() {
	vector<bool> answer(n, false);
	int lastKnown = -1;
	while (lastKnown < n - 1) {
		int l = lastKnown + 1, r = lastKnown + 1;
		if (p > 0)
			r += (double)1 / p;
		else
			r = n - 1;
		int x = r - l + 1;
		while (__builtin_popcount(x) != 1)
			r --, x --;
		r = min(r, n - 1);
		vector<bool> qry(n, false);
		for (int i = l; i <= r; i ++)
			qry[i] = true;
		if (!test_students(qry)) {
			lastKnown = r;
			continue;
		}
		int pos = 0;
		for (int pas = 1 << 20; pas; pas >>= 1) {
			if (l + pos + pas - 1 < r) {
				vector<bool> qry(n, false);
				for (int j = l; j <= l + pos + pas - 1; j ++)
					qry[j] = true;
				if (!test_students(qry))
					pos += pas;
			}
		}
		answer[l + pos] = true;
		lastKnown = l + pos;
	}
	return answer;
}

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