Submission #951336

# Submission time Handle Problem Language Result Execution time Memory
951336 2024-03-21T15:48:16 Z GrandTiger1729 Toxic Gene (NOI23_toxic) C++17
95.95 / 100
39 ms 600 KB
#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;
 
const int K = 8, T = 30;
vector<int> encode(vector<int> qry)
{
	int n = qry.size();
	vector<int> ret;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < (1 << i); j++)
		{
			ret.push_back(qry[i]);
		}
	}
	return ret;
}
void determine_type(int n)
{
	vector<int> ord(n);
	iota(ord.begin(), ord.end(), 1);
	string ans(n + 1, 'R');
	int cnt = 0;
	int tt = -1;
	vector<int> stk;
	int i = 0;
	while (cnt < T && i < n)
	{
		shuffle(ord.begin() + i, ord.end(), mt19937(time(0) + 777771449));
		int j = min(n, i + K);
		int xx = -1;
		{
			vector<int> qry;
			for (int k = i; k < j; k++)
			{
				qry.push_back(ord[k]);
			}
			int x = min(stk.size(), K - qry.size());
			for (int k = 0; k < x; k++)
			{
				qry.push_back(stk.end()[-1 - k]);
			}
			xx = query_sample(encode(qry));
			if (xx == (1 << qry.size()) - 1)
			{
				stk.insert(stk.end(), qry.begin(), qry.end());
				i = j;
				continue;
			}
			else
			{
				for (int k = j - i; k < qry.size(); k++)
				{
					ans[qry[k]] = (xx >> k & 1) ? 'S' : 'R';
				}
				for (int k = 0; k < x; k++)
				{
					stk.pop_back();
				}
			}
		}
		int l = i, r = j;
		while (l < r && xx >> (l - i) & 1)
		{
			l++;
		}
		auto make_query = [&](int mid)
		{
			vector<int> qry;
			for (int k = l; k < mid; k++)
			{
				qry.push_back(ord[k]);
			}
			int x = min(stk.size(), K - qry.size());
			for (int k = 0; k < x; k++)
			{
				qry.push_back(stk.end()[-1 - k]);
			}
			return qry;
		};
		while (l < r - 1)
		{
			int mid = (l + r) / 2;
			vector<int> qry = make_query(mid);
			int res = query_sample(encode(qry));
			if (res == (1 << qry.size()) - 1)
			{
				l = mid;
			}
			else
			{
				int x = qry.size() - (mid - l);
				for (int k = mid - l; k < qry.size(); k++)
				{
					ans[qry[k]] = (res >> k & 1) ? 'S' : 'R';
				}
				for (int k = 0; k < x; k++)
				{
					stk.pop_back();
				}
				r = mid;
			}
		}
		for (int k = 0; k < l - i; k++)
		{
			ans[ord[i + k]] = (xx >> k & 1) ? 'S' : 'R';
		}
		ans[ord[l]] = 'T';
		i = l + 1;
		tt = ord[l];
		cnt++;
	}
	while (i < n)
	{
		stk.push_back(ord[i++]);
	}
	while (stk.size())
	{
		int x = min((int)stk.size(), K);
		vector<int> qry;
		for (int k = 0; k < x; k++)
		{
			qry.push_back(stk.back());
			stk.pop_back();
		}
		auto tmp = encode(qry);
		tmp.push_back(tt);
		int res = query_sample(tmp);
		for (int k = 0; k < (int)qry.size(); k++)
		{
			ans[qry[k]] = (res >> k & 1) ? 'S' : 'R';
		}
	}
	for (int j = 1; j <= n; j++)
	{
		answer_type(j, ans[j]);
	}
}

Compilation message

toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (int k = j - i; k < qry.size(); k++)
      |                         ~~^~~~~~~~~~~~
toxic.cpp:94:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int k = mid - l; k < qry.size(); k++)
      |                           ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 32 ms 524 KB Output is correct
3 Correct 32 ms 348 KB Output is correct
4 Correct 32 ms 344 KB Output is correct
5 Correct 37 ms 500 KB Output is correct
6 Correct 37 ms 504 KB Output is correct
7 Correct 36 ms 344 KB Output is correct
8 Correct 38 ms 348 KB Output is correct
9 Correct 37 ms 348 KB Output is correct
10 Correct 36 ms 600 KB Output is correct
11 Correct 36 ms 348 KB Output is correct
12 Correct 32 ms 348 KB Output is correct
13 Correct 33 ms 344 KB Output is correct
14 Correct 34 ms 348 KB Output is correct
15 Partially correct 37 ms 348 KB Partially correct
16 Partially correct 37 ms 344 KB Partially correct
17 Partially correct 37 ms 344 KB Partially correct
18 Partially correct 38 ms 344 KB Partially correct
19 Correct 38 ms 348 KB Output is correct
20 Correct 38 ms 600 KB Output is correct
21 Correct 37 ms 348 KB Output is correct
22 Correct 32 ms 508 KB Output is correct
23 Correct 31 ms 348 KB Output is correct
24 Correct 33 ms 344 KB Output is correct
25 Correct 34 ms 348 KB Output is correct
26 Correct 33 ms 348 KB Output is correct
27 Correct 33 ms 344 KB Output is correct
28 Correct 34 ms 348 KB Output is correct
29 Correct 38 ms 348 KB Output is correct
30 Correct 37 ms 348 KB Output is correct
31 Correct 37 ms 348 KB Output is correct
32 Correct 39 ms 348 KB Output is correct
33 Correct 37 ms 344 KB Output is correct
34 Correct 37 ms 348 KB Output is correct
35 Partially correct 38 ms 344 KB Partially correct
36 Correct 5 ms 344 KB Output is correct