Submission #1042730

# Submission time Handle Problem Language Result Execution time Memory
1042730 2024-08-03T10:13:03 Z Tob COVID tests (CEOI24_covid) C++14
91.57 / 100
1520 ms 344 KB
#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;
	
	if (p >= 0.19) {
		for (int i = 0; i < n/3*3; i += 3) {
			if (!iv(i, i+2)) continue;
			res[i] = iv(i, i);
			if (res[i]) if (!iv(i+1, i+2)) continue;
			res[i+1] = iv(i+1, i+1);
			if (!res[i+1]) res[i+2] = 1;
			else res[i+2] = iv(i+2, i+2);
		}
		res[n-1] = iv(n-1, n-1);
		return res;
	}
	
	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

Main.cpp: In function 'std::vector<bool> find_positive()':
Main.cpp:71:24: warning: unused variable 'br' [-Wunused-variable]
   71 |    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: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:102:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 344 KB Output is correct (P=0.001, F=15.1, Q=10.9) -> 90.00 points
2 Correct 85 ms 344 KB Output is correct (P=0.005256, F=51.1, Q=46.5) -> 90.00 points
3 Correct 186 ms 344 KB Output is correct (P=0.011546, F=94.9, Q=94.7) -> 90.00 points
4 Correct 390 ms 344 KB Output is correct (P=0.028545, F=191.5, Q=191.0) -> 90.00 points
5 Correct 481 ms 344 KB Output is correct (P=0.039856, F=246.3, Q=244.0) -> 90.00 points
6 Correct 745 ms 344 KB Output is correct (P=0.068648, F=366.2, Q=365.8) -> 90.00 points
7 Correct 988 ms 344 KB Output is correct (P=0.104571, F=490.3, Q=493.5) -> 87.71 points
8 Correct 1270 ms 344 KB Output is correct (P=0.158765, F=639.1, Q=633.1) -> 90.00 points
9 Correct 1520 ms 344 KB Output is correct (P=0.2, F=731.4, Q=750.3) -> 81.57 points