The Cordillera Oriental is a mountain range in the Andes that stretches across Bolivia.
It consists of a sequence of mountain peaks, numbered from
to
.
The height of peak
(
) is
, which is an integer between
and
, inclusive.
For any two peaks and
where
, the distance between them is defined as
.
According to ancient Inca legends, a triple of peaks is mythical if it has the following special property: the heights of the three peaks match their pairwise distances ignoring the order.
Formally, a triple of indices is mythical if
, and
- the heights
match the pairwise distances
ignoring the order. For example, for indices
the pairwise distances are
, so the heights
,
, and
all match them, but the heights
do not match them.
This problem consists of two parts, with each subtask associated with either Part I or Part II. You may solve the subtasks in any order. In particular, you are not required to complete all of Part I before attempting Part II.
Part I
Given a description of the mountain range, your task is to count the number of mythical triples.
Implementation Details
You should implement the following procedure.
long long count_triples(std::vector<int> H)
: array of length
, representing the heights of the peaks.
- This procedure is called exactly once for each test case.
The procedure should return an integer , the number of mythical triples in the mountain range.
Constraints
for each
such that
.
Subtasks
Part I is worth a total of points.
Subtask | Score | Additional Constraints |
---|---|---|
1 | ||
2 | ||
3 | ||
4 | The heights are non-decreasing. That is, |
|
5 | ||
6 | No additional constraints. |
Example
Consider the following call.
count_triples([4, 1, 4, 3, 2, 6, 1])
There are mythical triples in the mountain range:
- For
, the heights
match the pairwise distances
.
- For
, the heights
match the pairwise distances
.
- For
, the heights
match the pairwise distances
.
Hence, the procedure should return .
Note that the indices do not form a mythical triple, as the heights
do not match the pairwise distances
.
Part II
Your task is to construct mountain ranges with many mythical triples. This part consists of output-only subtasks with partial scoring.
In each subtask, you are given two positive integers and
, and you should construct a mountain range with at most
peaks.
If your solution contains at least
mythical triples, you will receive the full score for this subtask.
Otherwise, your score will be proportional to the number of mythical triples your solution contains.
Note that your solution must consist of a valid mountain range.
Specifically, suppose your solution has peaks (
must satisfy
).
Then, the height of peak
(
), denoted by
, must be an integer between
and
, inclusive.
Implementation Details
You should implement the following procedure.
std::vector<int> construct_range(int M, int K)
: the maximum number of peaks.
: the desired number of mythical triples.
- This procedure is called exactly once for each subtask.
The procedure should return an array of length
, representing the heights of the peaks.
At the IOI, there are two methods to submit your solution: you could either submit one output file to each subtask, or implement a procedure call.
Unfortunately, an output-only format is not currently possible on DMOJ since any files you submit can be at most characters long. Instead,
you will submit a program that will be run on the test cases like for a normal problem. The time limit for these subtasks will be 60 seconds.
Subtasks and Scoring
Part II is worth a total of points.
For each subtask, the values of
and
are fixed and given in the following table:
Subtask | Score | ||
---|---|---|---|
7 | |||
8 | |||
9 | |||
10 | |||
11 | |||
12 |
For each subtask, if your solution does not form a valid mountain range, your score will be (reported as
Output isn't correct
in CMS).
Otherwise, let denote the number of mythical triples in your solution.
Then, your score for the subtask is:
5 \cdot \min\left(1,\frac{T}{K}\right).
Sample Grader
Parts I and II use the same sample grader program, with the distinction between the two parts determined by the first line of the input.
Input format for Part I:
1
N
H[0] H[1] ... H[N-1]
Output format for Part I:
T
Input format for Part II:
2
M K
Output format for Part II:
N
H[0] H[1] ... H[N-1]
Note that the output of the sample grader matches the required format for the output file in Part II.
Note
This problem has different time limits for the second part. If you exceed the Time Limit for any case in part II, the judge will incorrectly display >2.000s
regardless of the actual time taken. Refer to the Part II section for the part-specific time limit.
Attachment Package
The sample grader along with sample test cases are available here.
Comments