#P6241. [eJOI 2019] 塔
[eJOI 2019] 塔
Description
Jernej feels very bored at night, so he invents a game. He wants to use number cards to build a tower. At the beginning, he writes the number on a card.
Jernej may write a new number on another card and place it on the top of the tower. This new number must be equal to the sum of the numbers in some consecutive segment of the current tower. In other words, suppose there are already numbers in the tower. You may choose any segment in the tower, compute the sum of this segment, and add the resulting new number to the top of the tower, where .
Jernej wants to build towers (equivalently, multiple queries). The top number of each tower is one of (possibly different) target numbers he wants. You need to help him find the minimum number of steps to build these towers and output a corresponding plan.
Input Format
The first line contains an integer , the number of towers.
The next lines each contain an integer , meaning Jernej wants to build a tower whose top number is .
It is guaranteed that a solution exists.
Output Format
For each query :
- Output one line containing an integer (), the minimum number of steps.
- Then output lines, each containing two integers separated by a space, describing the plan to build the tower (print earlier operations first).
3
2
3
7
2
1 1
1 2
3
1 1
2 2
1 3
4
1 1
1 2
2 3
1 4
Hint
Special Judge Scoring Rules
This problem has test points. For each test point, the scoring rules are:
- For any tower in the test point, if the minimum number of steps output by your program is exactly the same as the standard answer, then you will get points for this test point.
- For any tower in the test point, if your program’s output is incorrect, you get points (during judging, if the output is incomplete you may get UKE).
- If your answer is not optimal but still correct, then for the -th tower in this test point, your score is $\text{score}_i =1+\dfrac{\text{minimum steps}}{\text{solution steps}}\times 7$, where is the minimum number of steps in the correct answer, and is the answer output by your program. The final score of this test point is . Round up to two decimal places.
Sample Input/Output Explanation
Query 1 Explanation:
- Jernej wants to build a tower with top number . Initially the tower is (the left side is the bottom and the right side is the top).
- Step 1: choose segment , sum all elements in to get , now the tower is .
- Step 2: choose segment , sum all elements in to get , now the tower is . The requirement of the query is now satisfied.
Query 2 Explanation:
- There is more than one way to build a tower whose top is . Besides the one in the sample output, the following is also a correct answer:
1 1
1 2
2 3
Constraints
This problem uses bundled testdata and has 7 subtasks.
- Subtask 1 (1 test case - 10 points): .
- Subtask 2 (1 test case - 10 points): .
- Subtask 3 (1 test case - 10 points): .
- Subtask 4 (1 test case - 10 points): .
- Subtask 5 (1 test case - 10 points): .
- Subtask 6 (1 test case - 10 points): .
- Subtask 7 (1 test case - 10 points): .
- Subtask 8 (1 test case - 10 points): .
- Subtask 9 (2 test cases - 20 points): no additional constraints.
For all testdata, it is guaranteed that .
Notes
The original problem is from: eJOI2019 Problem D. Tower.
Translation provided by: @_Wallace_.
Translated by ChatGPT 5
京公网安备 11011102002149号