#P16217. [ECUSTPC 2025] 克隆之击
[ECUSTPC 2025] 克隆之击
Problem Description
Maddy and Baddy decide to compete in a battle of wits.
Initially, Maddy and Baddy have a multiset of positive integers: $S = \{a_1, a_1 + d, a_1 + 2d, \dots, a_1 + (n-1)d\}$. They decide to play a game with the following rules:
- Maddy moves first, and Maddy and Baddy take turns.
- On each move, the current player must add one positive integer into .
- The game ends after each player has made moves.
- Maddy’s goal is to make the final -connectivity number of as large as possible, while Baddy’s goal is to make it as small as possible.
The -connectivity number is defined as follows:
- First sort . For each pair of adjacent numbers, if their difference is greater than , increase the connectivity number by 1. The connectivity number starts at 1.
- An equivalent definition is: build a graph where each element of is a vertex, and add an edge between two vertices if their difference is at most . The -connectivity number is the number of connected components.
Assume both Maddy and Baddy are perfectly smart and always choose the best strategy. Please compute the value of the -connectivity number when the game ends.
Input Format
The first line contains an integer (), the number of test cases.
For each test case, the only line contains five integers and (, ), representing the initial size of , the first term and common difference of the arithmetic progression, the number of rounds, and the parameter , respectively.
Output Format
For each test case, output one integer in one line, meaning the -connectivity number of at the end of the game when both Maddy and Baddy play optimally.
4
3 2 3 2 2
4 3 2 5 1
4 1 1 5 2
9 7 8 3 0
3
6
6
12
Hint
Explanation for Sample 1
For the first sample, the initial $S = \{(2 + 0 \times 3), (2 + 1 \times 3), (2 + 2 \times 3)\} = \{2, 5, 8\}$. One possible sequence of moves is:
- Maddy adds 13, .
- Baddy adds 3, .
- Maddy adds 18, .
- Baddy adds 7, .
After sorting, the adjacent differences are , , , , , . There are 2 differences greater than , so the -connectivity number is 3.
Translated by ChatGPT 5