Submission #1133768

#TimeUsernameProblemLanguageResultExecution timeMemory
1133768PagodePaivaCOVID tests (CEOI24_covid)C++17
Compilation error
0 ms0 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;
	double aux = (1.0-P);
	int d = 1;
	while(aux > 0.5){
		d++;
		aux *= (1.0-P);
	}
	//cout << d << endl;
	for(int i = 0;i < N;){
		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){
			int ll = i, rr = r;
			int answ = i;
			while(ll <= rr){
				int mid = (ll+rr)/2;
				for(int j = ll;j <= mid;j++){
					query[pos[j]] = true;
				}
				res = test_students(query);
				for(int j = ll;j <= mid;j++){
					query[pos[j]] = false;
				}				
				if(res) {
					ans = mid;
					rr = mid-1;
				}
				else{
					ll = mid+1;
				}
			}
			ans[pos[answ]] = true;
			i = answ+1;
		}
		else{
			i += d;
		}
	}
	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 'std::vector<bool> find_positive()':
Main.cpp:97:47: error: no match for 'operator=' (operand types are 'std::vector<bool>' and 'int')
   97 |                                         ans = mid;
      |                                               ^~~
In file included from /usr/include/c++/11/vector:68,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/11/bits/stl_bvector.h:736:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(const std::vector<bool, _Alloc>&) [with _Alloc = std::allocator<bool>]'
  736 |       operator=(const vector& __x)
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_bvector.h:736:31: note:   no known conversion for argument 1 from 'int' to 'const std::vector<bool>&'
  736 |       operator=(const vector& __x)
      |                 ~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_bvector.h:767:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::vector<bool, _Alloc>&&) [with _Alloc = std::allocator<bool>]'
  767 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_bvector.h:767:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<bool>&&'
  767 |       operator=(vector&& __x) noexcept(_Bit_alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_bvector.h:792:7: note: candidate: 'std::vector<bool, _Alloc>& std::vector<bool, _Alloc>::operator=(std::initializer_list<bool>) [with _Alloc = std::allocator<bool>]'
  792 |       operator=(initializer_list<bool> __l)
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_bvector.h:792:40: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<bool>'
  792 |       operator=(initializer_list<bool> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~^~~
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:117:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:133:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~