#P14037. [PAIO 2025] XOR multiset
[PAIO 2025] XOR multiset
题目背景
DO NOT include xor.h
. Submit using C++ >=17.
题目描述
You are given an integer and non-negative integers .
Find a multiset of integers from such that:
- is maximized, where denotes the bitwise XOR operation. The bitwise XOR operator works on the binary representation of two numbers and performs the logical exclusive OR operation on each pair of corresponding bits; so 5 (binary representation 0101) XOR 3 (binary representation 0011) gives 6 (binary representation 0110). The operator is
^
in C++, Java, and Python.
If there are multiple such multisets, you can return any of them.
Implementation Details
You need to implement the following function:
(int64, int32[]) find_multiset(int32 n, int64[] a)
- : the modulus value
- : array of length , where corresponds to
- The function should return a pair with:
- First element: an integer representing the optimal value of among all valid multisets
- Second element: a vector representing any optimal multiset . The elements of the vector should be integers from to , and the size of has to be at most .
提示
Examples
The following find_multiset(3, {5, 10})
call should return {15, {1, 2}}
- We have and (corresponding to ).
- We need to find a multiset such that .
- Valid multisets include: (sum = 0), (sum = 3 0), (sum = 3 0), (sum = 6 0), etc.
- For : XOR is .
- For : XOR is $a_1 \oplus a_1 \oplus a_1 = 5 \oplus 5 \oplus 5 = 5$.
- The maximum XOR value is 15, achieved by .
The following find_multiset(4, {8, 12, 6})
call should return {14, {1, 3}}
- We have and (corresponding to ).
- We need to find a multiset such that .
- For : XOR is .
- For : XOR is .
- The maximum XOR value is 14, achieved by .
Sample Grader
The sample grader reads the input in the following format:
- Line 1: One integer
- Line 2: integers
The sample grader calls find_multiset(n, a)
and prints the returned multiset in the following format:
- First line: the value returned as the first element of the pair
- Second line: the size of the multiset
- Third line: the elements of the multiset (if any), separated by spaces
Note: The sample grader provided with this problem is just for testing your solution locally. The actual grader used during the contest may be different.
Constraints
- for each
Scoring
- Subtask 1 (20 points):
- Subtask 2 (40 points): is odd
- Subtask 3 (40 points): No additional constraints
In each subtask, you can obtain a partial score if your program determines the optimal value of among all valid multisets . More precisely, you get the whole score of a subtask if in all of its test cases, the first element of the pair returned by find_multiset
is exactly the same as the first element of the pair returned by the official grader and the second element is a valid multiset (i.e. it satisfies the conditions above) that achieves this optimal value. You get 60% of the score of a subtask if in all of its test cases, the first element of the pair returned by find_multiset
is exactly the same as the first element of the pair returned by the official grader (regardless of the second element) and you get 0% of the score of a subtask otherwise.