#P5208. Determine the Prices
Determine the Prices
Determine the Prices
Three friends, V, I, and Y, are involved in an interesting pricing puzzle. I has opened a store that sells items (numbered from to ) with an infinite supply. Each item is priced either or . V knows through supernatural means that among these items, the number of items priced is exactly odd or even, as indicated by a parameter, and additionally, there is at least one item with price .
V does not want to ask I directly. Instead, he employs Y to run errands. In each query, V provides two non-empty sets and (each containing distinct item indices). Y will go to the store, purchase the items in both sets, and then tell V which set has a higher total price. Formally, if (\sum_{i \in S} price_i > \sum_{i \in T} price_i) the response is 0; if (\sum_{i \in T} price_i > \sum_{i \in S} price_i) the response is 1; and if they are equal, Y returns an answer by some unknown rule. The cost of a query is defined as . Moreover, the total cost cannot exceed a given threshold (Y’s energy limit).
Your task is to determine the price of each of the items by judiciously making queries.
You are required to implement the function find_price(task_id, N, K, ans)
where:
task_id
is the subtask identifier.N
is the number of items.K
indicates the parity constraint: if , then an even number of items are priced ; if , then an odd number of items are priced .ans
is an array where your computed price for item should be stored inans[i]
.
You can make queries via a function query(S, nS, T, nT)
that takes two arrays of item indices with their sizes nS
and nT
, respectively, and returns (a) 0 if the sum of prices of set is greater, (b) 1 if the sum of prices of set is greater, and (c) an unknown response if the sums are equal. Note that each query has a cost of .
For the purpose of this problem, you do not need to implement the interactive query functionality. Instead, design an algorithm that solves the problem under the given constraints. In our sample solution below, we provide a trivial answer that meets the parity condition.
Note: In interactive problems, you should carefully design the queries so as not to exceed the total allowed cost .
inputFormat
Input consists of three integers on a single line: task_id
, N
, and K
. task_id
represents the subtask identifier, N
is the number of items, and K
indicates the required parity condition ( for even and for odd number of items priced ).
outputFormat
Output a single line containing N
space-separated integers, where the i-th integer is the determined price of item i (either 0 or 1).
sample
0 1 1
1