Submission #1042760

#TimeUsernameProblemLanguageResultExecution timeMemory
1042760TobCOVID tests (CEOI24_covid)C++14
100 / 100
1417 ms344 KiB
#include <bits/stdc++.h>

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

int N;

double P;

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

vector<bool> find_positive() {
	int n = N, d = 1, d_ = 0;
	double p = P;
	
	auto iv = [&](int l, int r) {
		vector <bool> v(n, 0);
		for (int i = l; i <= r; i++) v[i] = 1;
		return test_students(v);
	};
	
	vector <bool> res(n, 0);
	if (!p) return res;
	if (p >= 0.3) {
		for (int i = 0; i < n; i++) res[i] = iv(i, i);
		return res;
	}
	
	double cur = 1-p;
	while (cur >= 0.5) cur *= 1-p, d_++;
	while (d < d_) d *= 2;
	if (p < 0.1) d /= 2;
	else if (p < 0.12) d--;
	else d = d_;
	
	for (int i = 0; i < n; i += d) {
		int r = min(n, i+d)-1;
		while (i <= r && iv(i, r)) {
			int lo = i, hi = r, br = 0;
			while (lo < hi) {
				int mid = (lo + hi - 1) / 2;
				if (iv(lo, mid)) hi = mid;
				else lo = mid+1;
			}
			res[lo] = 1;
			r = min(n-1, lo+d);
			i = lo+1;
		}
	}

    return res;
}

int main() {
    int T;
    scanf("%d %lf %d", &N, &P, &T);
    
    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 'std::vector<bool> find_positive()':
Main.cpp:60:24: warning: unused variable 'br' [-Wunused-variable]
   60 |    int lo = i, hi = r, br = 0;
      |                        ^~
Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...