Submission #1045072

#TimeUsernameProblemLanguageResultExecution timeMemory
1045072TsovakCOVID tests (CEOI24_covid)C++17
52.71 / 100
1809 ms344 KiB
// -------------------- Includes -------------------- //
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <array>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <cassert>
#include <assert.h>
#include <climits>
#include <limits.h>
#include <ctime>
#include <time.h>
#include <random>
#include <chrono>
#include <fstream>
using namespace std;

// -------------------- Typedefs -------------------- //

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;

// -------------------- Defines -------------------- //

#define pr pair
#define mpr make_pair
#define ff first
#define ss second

#define mset multiset
#define mmap multimap
#define uset unordered_set
#define umap unordered_map
#define umset unordered_multiset
#define ummap unordered_multimap
#define pqueue priority_queue

#define sz(x) (int((x).size()))
#define len(x) (int((x).length()))
#define all(x) (x).begin(), (x).end()
#define clr(x) (x).clear()

#define ft front
#define bk back
#define pf push_front
#define pb push_back
#define popf pop_front
#define popb pop_back

#define lb lower_bound
#define ub upper_bound
#define bs binary_search

// -------------------- Constants -------------------- //

const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18 + 5);
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);

// -------------------- Solution -------------------- //

int N;
double P;

inline 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> ans, vans;

bool qry(int l, int r)
{
	vector<bool> msk(N, 0);
	for (int i = l; i <= r; i++) msk[i - 1] = 1;

	return test_students(msk);
}

int calc(int tl, int tr)
{
	if (tl == tr) {
		if (qry(tl, tl)) {
			ans[tl - 1] = 1;
			return tl;
		}

		ans[tl - 1] = 0;
		return -1;
	}

	int m = (tl + tr) / 2;


	if (qry(tl, m)) {
		if (tl == m) {
			ans[tl - 1] = 1;
			return tl;
		}
		return calc(tl, m);
	}
	for (int i = tl; i <= m; i++) ans[i - 1] = 0;

	if (qry(m + 1, tr)) {
		if (m + 1 == tr) {
			ans[m] = 1;
			return m + 1;
		}
		return calc(m + 1, tr);
	}
	for (int i = m + 1; i <= tr; i++) ans[i - 1] = 0;

	return - 1;
}

vector<bool> find_positive()
{
	int i, j;

	int h = max(1, int(db(N) * P));

	int len;
	
	if (h == 1) len = 1000;
	else if (h <= 5) len = 175;
	else if (h <= 11) len = 76;
	else if (h <= 28) len = 33;
	else if (h <= 39) len = 20;
	else if (h <= 68) len = 12;
	else if (h <= 104) len = 7;
	else if (h <= 158) len = 6;
	else len = 3;

	int e;

	for (i = 1; i <= N; i) {
		e = calc(i, min(N, i + len - 1));
		if (e == -1) i += len;
		else i = e + 1;
	}

	return ans;
}

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

	ans.resize(N);

	for (int i = 0; i < T; i++) {
		vector<bool> answer = find_positive();
		assert(answer.size() == (size_t)N);

		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:173:22: warning: for increment expression has no effect [-Wunused-value]
  173 |  for (i = 1; i <= N; i) {
      |                      ^
Main.cpp:155:9: warning: unused variable 'j' [-Wunused-variable]
  155 |  int i, j;
      |         ^
Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:103:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |  scanf(" %c", &answer);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:185:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |  scanf("%d %lf %d", &N, &P, &T);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:201:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  201 |   scanf(" %c", &verdict);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...