#P8367. [LNOI2022] 盒
[LNOI2022] 盒
Problem Description
There are distinct boxes in a row. Initially, the -th box contains items, and the total number of items is . For a non-negative integer array satisfying , consider the following problem:
You want the -th box to contain exactly items. To achieve this, you may perform the following operation any number of times: for two adjacent boxes, move exactly one item from one box to the other. The cost of performing one operation on boxes and () is . Note: moving one item from box to box and moving one item from box to box both cost . You must ensure that during the operations, no box ever has a negative number of items.
Under the above setting, define the minimum cost to reach a state where the -th box contains exactly items from the initial state as . You need to compute, over all non-negative integer arrays satisfying , the sum of . Output the answer modulo .
Input Format
This problem has multiple test cases. The first line contains a positive integer , the number of test cases.
For each test case, the input consists of three lines. The first line contains a positive integer , the number of boxes. The second line contains non-negative integers describing the initial state. The third line contains non-negative integers describing the cost of moving items.
Output Format
For each test case, output one integer per line: the sum, over all non-negative integer arrays satisfying , of the minimum cost to reach the target state, modulo .
2
2
2 3
65472
5
1 3 2 1 1
2 3 3 3
589248
8589
Hint
[Sample Explanation #1]
For the first test case, there are six cases to consider. The pairs are .
In the first case, at least moves are needed, and the minimum cost is .
In the second case, at least move is needed, and the minimum cost is .
In the third case, no operation is needed, and the minimum cost is .
In the fourth case, at least move is needed, and the minimum cost is .
In the fifth case, at least moves are needed, and the minimum cost is .
In the last case, at least moves are needed, and the minimum cost is .
Therefore, the sum of minimum costs is $130944 + 65472 + 0 + 65472 + 130944 + 196416 = 589248$.
[Sample #2]
See box/box2.in and box/box2.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #3]
See box/box3.in and box/box3.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #4]
See box/box4.in and box/box4.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #5]
See box/box5.in and box/box5.ans in the attachment.
This sample satisfies the constraints of test points .
[Sample #6]
See box/box6.in and box/box6.ans in the attachment.
This sample satisfies the constraints of test points .
[Constraints]
It is guaranteed that for every test point and every test case: , , , and .
| Test Point ID | Special Properties | |||
|---|---|---|---|---|
| A | ||||
| None | ||||
| B | ||||
| AC | ||||
| None | ||||
Special Property A: For any , .
Special Property B: For any , .
Special Property C: There are at most indices such that .
[Hint]
Some test points have a large input size. To optimize runtime, it is recommended to use a faster input method.
Translated by ChatGPT 5