시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
10 초 (추가 시간 없음) | 1024 MB | 0 | 0 | 0 | 0.000% |
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 S mysterious road signs with numbers on both sides. The i-th sign (numbered in order from west to east) is at a point Di kilometers east of Signfield, and has a number Ai on the west-facing side and a number Bi 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:
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, T. T test cases follow. Each begins with one line containing one integer S: the number of road signs. Then, S more lines follow. The i-th of these lines represents the i-th sign (in west-to-east order), and contains three integers Di, Ai, and Bi: 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 x
is the test case number (starting from 1), and y
and z
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
In Sample Case #1, there is only one sign. If we choose just that sign as our set, there are many possible values of M and N that work — for example:
So, the set consisting of just that one sign is valid. That is the only set of that length, so the answer is 1 1
.
In Sample Case #2, note that the first, second, fourth, and fifth signs would be consistent with M = 9 and N = -1, 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 M/N pairs that make the second set of three signs valid, that set counts only once:
In Sample Case #3, the entire sequence is a valid set, with M = 4 and N = 2.
Contest > Google > Code Jam > Google Code Jam 2018 > Round 1B B번