IOI '19 P4 - Broken Line
View as PDFAzerbaijan is famous for its carpets.
As a master carpet designer you want to make a new design by drawing a broken line.
A broken line is a sequence of  line segments in a two-dimensional plane, which is defined by a sequence of 
 points 
 as follows.
For each 
 there is a segment connecting points 
 and 
.
In order to make the new design, you have already marked  dots in a two-dimensional plane.
The coordinates of dot 
 
 are 
.
No two dots have the same x or the same y coordinate.
You now want to find a sequence of points , which defines a broken line that
- starts at 
(that is,
and
),
 - contains all of the dots (not necessarily as the endpoints of the segments), and
 - consists solely of horizontal or vertical segments (two consecutive points defining the broken line have an equal x or y coordinate).
 
The broken line is allowed to intersect or overlap itself in any way. Formally, each point of the plane may belong to any number of segments of the broken line. Your score will depend on the number of segments in the broken line (see Scoring below).
At IOI, this was an output-only task.
You were given the  input files and had to submit a zip file containing your solutions to the test cases.
Unfortunately, a similar 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.
This means it will read the input file from standard input and write the solution to standard output.
We will still provide you with the input files, and the time limit for the problem will be very high.
You can use the value of 
 and the first point to determine which case your program is being run on if you want to write a solution with significantly different behaviour on the different test cases.
Input Specification
Each input file is in the following format:
- line 
:
 - line 
(for
):
 
Output Specification
Your solution must output the broken line in the following format:
- line 
:
 - line 
(for
):
 
Note that the second line should contain  and 
 (i.e., the output should not contain 
 and 
).
Each 
 and 
 should be an integer.
Example
For the sample input:
4
2 1
3 3
4 4
5 2
a possible valid output is
6
2 0
2 3
5 3
5 2
4 2
4 4
Please note this example is not among the actual inputs of this task.
Constraints
- All values of 
and
are integers.
 - No two dots have the same 
or the same
coordinates, i.e.
and
for
.
 
Scoring
For each test case, you can get up to  points.
Your output for a test case will get 
 points if it does not specify a broken line with the required properties.
Otherwise, the score will be determined using a decreasing sequence 
, which varies by test case.
Assume that your solution is a valid broken line consisting of segments. Then, you will get
points, if
(for
),
points, if
(for
),
points, if
,
points, if
.
The sequence  for each test case is given below.
| Test cases | 01 | 02 | 03 | 04 | 05 | 06 | 07-10 | 
|---|---|---|---|---|---|---|---|
Visualizer
In the attachments of this task, there is a script that allows you to visualize input and output files.
To visualize an input file, use the following command:
python vis.py [input file]
You can also visualize your solution for some input, using the following command. Due
to technical limitations, the provided visualizer shows only the first  segments of
the output file.
python vis.py [input file] --solution [output file]
Example:
python vis.py examples/00.in --solution examples/00.out
Note that the visualizer depends on the matplotlib package which you will have to install yourself.
Attachment Package
The test cases and the visualizer are available here.
Comments