Submission #950959

# Submission time Handle Problem Language Result Execution time Memory
950959 2024-03-21T03:09:14 Z GrandTiger1729 Toxic Gene (NOI23_toxic) C++17
38.7529 / 100
94 ms 1544 KB
#include "toxic.h"
#include <bits/stdc++.h>
using namespace std;

const int K = 8;
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);
	// random_shuffle(ord.begin(), ord.end());
	string ans(n + 1, 'R');
	int tt = -1;
	vector<int> stk;
	int i = 0;
	while (i < n)
	{
		int j = min(n, i + K);
		{
			vector<int> qry;
			for (int k = i; k < j; k++)
			{
				qry.push_back(ord[k]);
			}
			int res = query_sample(encode(qry));
			if (res == (1 << qry.size()) - 1)
			{
				stk.insert(stk.end(), qry.begin(), qry.end());
				i = j;
				continue;
			}
		}
		cerr << "HERE" << endl;
		auto make_query = [&](int mid)
		{
			vector<int> qry;
			for (int k = i; 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;
		};
		int l = i, r = j;
		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
			{
				r = mid;
			}
		}
		vector<int> qry = make_query(l);
		auto tmp = encode(qry);
		tmp.push_back(ord[l]);
		int res = query_sample(tmp);
		for (int k = 0; k < qry.size(); k++)
		{
			ans[qry[k]] = (res >> k & 1) ? 'S' : 'R';
		}
		cerr << "ans " << ans << endl;
		ans[ord[l]] = 'T';
		int x = min((int)stk.size(), K - (l - i + 1));
		for (int k = 0; k < x; k++)
		{
			stk.pop_back();
		}
		cerr << "OK " << l << ' ' << ord[l] << endl;
		i = l + 1;
		tt = ord[l];
	}
	cerr << ans << endl;
	for (int j = 0; j < stk.size(); j++)
	{
		cerr << stk[j] << endl;
	}
	cerr << "tt " << tt << endl;
	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';
		}
	}
	cerr << ans << endl;
	for (int j = 1; j <= n; j++)
	{
		answer_type(j, ans[j]);
	}
}

Compilation message

toxic.cpp: In function 'void determine_type(int)':
toxic.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for (int k = 0; k < qry.size(); k++)
      |                   ~~^~~~~~~~~~~~
toxic.cpp:95:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |  for (int j = 0; j < stk.size(); j++)
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Partially correct 84 ms 1116 KB Partially correct
3 Partially correct 75 ms 868 KB Partially correct
4 Partially correct 94 ms 1104 KB Partially correct
5 Partially correct 82 ms 1420 KB Partially correct
6 Partially correct 77 ms 1492 KB Partially correct
7 Partially correct 80 ms 1380 KB Partially correct
8 Partially correct 82 ms 1424 KB Partially correct
9 Partially correct 81 ms 1464 KB Partially correct
10 Partially correct 83 ms 1544 KB Partially correct
11 Partially correct 79 ms 1464 KB Partially correct
12 Partially correct 71 ms 1016 KB Partially correct
13 Partially correct 84 ms 928 KB Partially correct
14 Partially correct 76 ms 940 KB Partially correct
15 Partially correct 74 ms 1344 KB Partially correct
16 Partially correct 68 ms 1516 KB Partially correct
17 Partially correct 69 ms 1296 KB Partially correct
18 Partially correct 69 ms 1428 KB Partially correct
19 Partially correct 73 ms 1396 KB Partially correct
20 Partially correct 70 ms 1340 KB Partially correct
21 Partially correct 67 ms 1428 KB Partially correct
22 Partially correct 71 ms 1008 KB Partially correct
23 Partially correct 71 ms 1108 KB Partially correct
24 Partially correct 80 ms 1132 KB Partially correct
25 Partially correct 93 ms 980 KB Partially correct
26 Partially correct 79 ms 1104 KB Partially correct
27 Partially correct 77 ms 1104 KB Partially correct
28 Partially correct 78 ms 1104 KB Partially correct
29 Partially correct 90 ms 1360 KB Partially correct
30 Partially correct 91 ms 1432 KB Partially correct
31 Partially correct 87 ms 1364 KB Partially correct
32 Partially correct 84 ms 1364 KB Partially correct
33 Partially correct 94 ms 1360 KB Partially correct
34 Partially correct 77 ms 1364 KB Partially correct
35 Partially correct 66 ms 1428 KB Partially correct
36 Partially correct 9 ms 344 KB Partially correct