#P13140. [GCJ 2018 #1B] Mysterious Road Signs
[GCJ 2018 #1B] Mysterious Road Signs
题目描述
The town of Signfield is on a perfectly straight and infinitely long road running from west to east. Along that road, there is a sequence of mysterious road signs with numbers on both sides. The -th sign (numbered in order from west to east) is at a point kilometers east of Signfield, and has a number on the west-facing side and a number on the east-facing side.
Nobody in Signfield knows what these signs are trying to say. You think that the numbers on the west sides of the signs are intended for drivers traveling east, and that they represent distances to some particular destination. Similarly, you think that the numbers on the east sides of the signs are for drivers traveling west, and that they represent distances to some particular destination. You suspect that not all of the signs may be consistent with this theory, though.
To start testing your theory, you are interested in finding valid sets of signs that obey the following rules:
- The set is a contiguous subsequence of the sequence of all road signs. (The entire sequence also counts as a contiguous subsequence.)
- There exist locations and kilometers east of Signfield, where and are (not necessarily positive and not necessarily distinct) numbers, such that for every sign in that set, at least one of the following is true:
- $\mathbf{D}_{\mathbf{i}}+\mathbf{A}_{\mathbf{i}}=\mathbf{M}$.
- $\mathbf{D}_{\mathbf{i}}-\mathbf{B}_{\mathbf{i}}=\mathbf{N}$.
What is the largest possible number of signs in a valid set as described above, and how many different valid sets of that size are there?
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each begins with one line containing one integer : the number of road signs. Then, more lines follow. The -th of these lines represents the -th sign (in west-to-east order), and contains three integers , and : the sign's distance (in kilometers) east of Signfield, the number on its west side, and the number on its east side.
输出格式
For each test case, output one line containing Case #x: y z
, where is the test case number (starting from 1), and and are the largest possible number of signs in a valid set and the number of valid sets of that size, as described in the problem statement.
3
1
1 1 1
5
2 7 12
6 3 11
8 10 1
11 11 12
13 9 14
5
1 3 3
2 2 2
3 1 1
4 2 2
5 3 3
Case #1: 1 1
Case #2: 3 2
Case #3: 5 1
提示
Sample Explanation
In Sample Case #1, there is only one sign. If we choose just that sign as our set, there are many possible values of and that work - for example:
- and
- and (remember that each sign only needs to be correct for one of its values; also, and might be in the same place as one or more signs, or Signfield itself)
- and ( might be west of Signfield)
- and ( and are not necessarily distinct)
- and ( might be east of )
So, the set consisting of just that one sign is valid. That is the only set of that length, so the answer is 11 .
In Sample Case #2, note that the first, second, fourth, and fifth signs would be consistent with and , but they do not form a contiguous subsequence. (The 1 on the back of the third sign cannot be used as if it were on the front.) As it turns out, there is no valid set of four signs. There are two different valid sets of three signs. Note that although there are two different pairs that make the second set of three signs valid, that set counts only once:
- the first, second, and third signs, with and
- the third, fourth, and fifth signs, with and or with and
In Sample Case #3, the entire sequence is a valid set, with and .
Limits
- .
- $1 \leqslant \mathbf{D}_{\mathbf{i}} \leqslant 10^{6}$, for all .
- , for all .
- $1 \leqslant \mathbf{A}_{\mathbf{i}} \leqslant 10^{6}$, for all .
- $1 \leqslant \mathbf{B}_{\mathbf{i}} \leqslant 10^{6}$, for all .
Test set 1 (10 Pts, Visible)
- for all test cases.
Test set 2 (20 Pts, Hidden)
- for all but 3 test cases.
- for 3 test cases.