#P7195. [IOI 2019] 折线

[IOI 2019] 折线

Background

You can download the input files here.

Problem Description

Azerbaijan is famous for its carpets. As a master carpet designer, you want to draw a polyline in your new design. A polyline is a sequence of line segments in the 2D plane consisting of tt segments. These segments are defined by a sequence of t+1t+1 points p0,,ptp_0,\ldots,p_t as follows: for every 0jt10\le j\le t- 1, there is a segment connecting points pjp_j and pj+1p_{j+1}.

To complete this new design, you have already marked nn small dots in the 2D plane. The coordinates of small dot ii (1<i<n1 < i < n) are (xi,yi)(x_i,y_i). There are no two small dots with the same xx coordinate or the same yy coordinate.

Now you want to find a point sequence (sx0,sy0),(sx1,sy1)(sxk,syk)(sx_0,sy_0),(sx_1, sy_1)\ldots (sx_k, sy_k) such that the polyline defined by this sequence satisfies:

  • The polyline starts from (0,0)(0,0) (i.e., sx0=0sx_0=0 and sy0=0sy_0=0),
  • The polyline passes through all small dots (they do not have to be endpoints of segments), and
  • The polyline consists only of horizontal and vertical segments (for any two consecutive points defining the polyline, their xx coordinates or their yy coordinates are equal).

The polyline may self-intersect or overlap in any way. Formally, each point on the plane may belong to any number of segments of the polyline.

This is a partial-scoring output-only problem. You will be given 1010 input files that specify the positions of the small dots. For each input file, you need to submit an output file describing a polyline that satisfies the requirements. For each output file that provides a valid polyline, your score depends on the number of segments in the polyline (see the Scoring section below).

You do not need to submit any source code for this problem.

Input Format

Each input file has the following format:

  • Line 11: nn.
  • Line 1+i1+i (here 1<in1<i\le n): xi yix_i\ y_i.

Output Format

Each output file must follow the format below:

  • Line 11: kk.
  • Line 1+j1+j (here 1jk1\le j\le k): sxj syjsx_j\ sy_j.

Note that the second line should contain sx1sx_1 and sy1sy_1 (that is, the output must not include sx0sx_0 and sy0sy_0). All sxjsx_j and syjsy_j must be integers.

4
2 1 
3 3
4 4
5 2
6
2 0
2 3
5 3
5 2
4 2
4 4

Hint

Sample explanation

This sample is not from any of the actual testdata; it is only meant to help you understand the statement.

The output shown is also only one possible output.

Constraints

  • 1n1051\le n\le 10^5.
  • 1xi,yi1091\le x_i,y_i\le 10^9.
  • All values of xix_i and yiy_i are integers.
  • There are no two small dots with the same xx coordinate or the same yy coordinate, i.e., for all i1i2i_1\not=i_2, we have xi1xi2x_{i_1}\not=x_{i_2} and yi1yi2y_{i_1}\not=y_{i_2}.
  • 2×109sxi,syj2×109-2\times 10^9\le sx_i,sy_j\le 2\times 10^9.
  • The size of each submitted file (whether an output file or a compressed file) must not exceed 15MB\text{15MB}.

Scoring

For each test case, you can score at most 1010 points. If you output an invalid polyline, you will get 00 points. Otherwise, your score is computed using a decreasing sequence c1,,c10c_1, \cdots, c_{10}.

Suppose your solution is a valid polyline with kk segments. Then you will get:

  • ii points, if k=cik=c_i (1i101 \le i \le 10).
  • i+cikcici+1i+\dfrac{c_i-k}{c_i-c_{i+1}} points, if ci+1<k<cic_{i+1} < k < c_i (1i91 \le i \le 9).
  • 00 points, if k>c1k > c_1.
  • 1010 points, if k<c10k < c_{10}.

This can be understood as follows: on the interval k(ci+1,ci)k \in (c_{i+1}, c_i), your score increases linearly as kk decreases. Once you score, the score is guaranteed to be within [1,10][1, 10].

Below is the information about nn and cic_i for each test case:

Test case nn c1c_1 c2c_2 c3c_3 c4c_4 c5c_5 c6c_6 c7c_7 c8c_8 c9c_9 c10c_{10}
11 2020 5050 4545 4040 3737 3535 3333 2828 2626 2525 2323
22 600600 1 2001\ 200 937937 674674 651651 640640 628628 616616 610610 607607 603603
33 5 0005\ 000 10 00010\ 000 7 6077\ 607 5 2135\ 213 5 1255\ 125 5 0815\ 081 5 0375\ 037 5 0205\ 020 5 0125\ 012 5 0085\ 008 5 0035\ 003
44 50 00050\ 000 100 000100 \ 000 75 33675\ 336 50 67150\ 671 50 35950\ 359 50 20350\ 203 50 04750\ 047 50 02550\ 025 50 01450\ 014 50 00950\ 009 50 00350\ 003
55 72 01872\ 018 144 036144\ 036 108 430108\ 430 72 82472\ 824 72 44672\ 446 72 25772\ 257 72 06772\ 067 72 04472\ 044 72 03372\ 033 72 02772\ 027 72 02172\ 021
66 91 89191\ 891 183 782183\ 782 138 292138\ 292 92 80192\ 801 92 37192\ 371 92 15692\ 156 91 94191\ 941 91 91891\ 918 91 90691\ 906 91 90091\ 900 91 89491\ 894
77 10510^5 2×1052\times 10^5 150 475150\ 475 100 949100\ 949 100 500100\ 500 100 275100\ 275 100 050100\ 050 100 027100\ 027 100 015100\ 015 100 009100\ 009 100 003100\ 003

Visualization tool

In the additional files for this problem, there is a script that can visualize the input files and output files.

To visualize an input file, use the following command:

python vis.py [input file]

For a given input, you can also visualize your solution with the command below. Due to technical limitations, the visualization tool only shows the first 10001000 segments in the output file.

python vis.py [input file] --solution [output file]

For example:

python vis.py examples/00.in --solution examples/00.out

Translated by ChatGPT 5