#P10675. 【MX-S1-T4】先见之明
【MX-S1-T4】先见之明
Background
Original problem link: https://oier.team/problems/S1D。
Problem Description
You are given non-negative integers 。There are queries, and for each query:
- Given a non-negative integer , you need to pick some elements (i.e., a subset, which may be empty) from such that their sum is 。
- Under the condition that the sum is , you need to minimize the sum. You only need to output this minimized sum.
- is given in binary form. Specifically, it is given in the form , and it is guaranteed that all are non-negative integers and strictly decreasing, i.e., 。
Since the answer may be very large, you only need to output the result modulo 。
If it is impossible to pick some elements from such that their sum is , output for that query.
Input Format
The first line contains two positive integers 。
The second line contains non-negative integers 。
The next lines describe the queries. Each line starts with a non-negative integer , followed by non-negative integers , representing 。It is guaranteed that are strictly decreasing, i.e., 。
Output Format
Output lines. Each line contains one integer, the answer modulo , or if there is no solution.
3 3
0 0 1
0
2 1 0
1 3
0
3
-1
见下发文件。
见下发文件。
Hint
Sample Explanation 1
Each is respectively. The values of in the three queries are: . Details:
- : choose the empty set.
- : choosing is enough.
- : no solution.
Sample Explanation 2
This sample satisfies the constraints of Subtask 。
Constraints
This problem uses bundled subtasks for judging.
For of the testdata, , , , , and 。
Blank entries in the table mean there are no additional constraints.
| Subtask ID | Special Property | Score | ||||
|---|---|---|---|---|---|---|
| All are distinct. | ||||||
Since the input size is large, we provide fast_read.cpp in the attached files for optional use (note that it may fail to compile under the C++98 standard).
It is guaranteed that the time limit is set to twice that of using standard std input without special input optimizations.
Translated by ChatGPT 5