Polygon Partition

시간 제한3초메모리 제한2048 MB

요약
단순 다각형의 꼭짓점이 주어질 때 경계 위의 반정수점을 모두 찾고, 그 바닥값들을 합이 같은 두 부분집합으로 나눌 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
기하, 수학, 동적 계획법, 구현
정답자
아직 제출이 없습니다

문제

A simple polygon is a polygon that is not self-intersecting and does not contain any holes. You are given the NN vertices of a simple polygon, v_1v\_1, v_2v\_2, \ldots, v_Nv\_N, where v_i=(x_i,y_i)v\_i = (x\_i, y\_i), and x_ix\_i and y_iy\_i are the xx-coordinate and yy-coordinate of the ithi^{\textrm{th}} vertex, respectively. The vertices are distinct and given in counterclockwise order (so there is an edge between each pair of consecutive vertices; there is also an edge from v_Nv\_N back to v_1v\_1).

The polygon's boundary does not pass through any lattice points (a lattice point is a point where both coordinates are integers). In addition, none of the x_ix\_i or y_iy\_i values are exactly an integer.

A semi-integer point is a point where exactly one of its coordinates is an integer. Let \mathcal{P} = \left\\{p\_1, p\_2, \ldots, p\_k\right\\} be all of the semi-integer points that lie on the boundary of the polygon. For each semi-integer point p_ip\_i in P\mathcal{P}, let n_in\_i be the floor of the non-integer coordinate of p_ip\_i. For a subset S\mathcal{S} of P\mathcal{P}, let σ(S)\sigma(\mathcal{S}) be the sum of the n_in\_i of the points in S\mathcal{S} (with σ(∅)=0\sigma(\emptyset) = 0). Does there exist a partition of P\mathcal{P} into two subsets S_1\mathcal{S}\_1 and S_2\mathcal{S}\_2 so that the σ(S_1)=σ(S_2)\sigma(\mathcal{S}\_1) = \sigma(\mathcal{S}\_2)?

(Two sets S_1\mathcal{S}\_1 and S_2\mathcal{S}\_2 are a partition of P\mathcal{P} if P=S_1∪S_2\mathcal{P} = \mathcal{S}\_1 \cup \mathcal{S}\_2 and S_1∩S_2=∅\mathcal{S}\_1 \cap \mathcal{S}\_2 = \emptyset. There are no other restrictions on S_1\mathcal{S}\_1 and S_2\mathcal{S}\_2 so long as these two conditions hold and σ(S_1)=σ(S_2)\sigma(\mathcal{S}\_1) = \sigma(\mathcal{S}\_2). In particular, empty sets are allowed, and the semi-integer points in each set do not have to be contiguous around the polygon boundary.)

입력

The first line of input contains one integer NN (3≤N≤5003 \leq N \leq 500), the number of vertices of the polygon.

Each of the next NN lines contains two space-separated real numbers x_ix\_i and y_iy\_i (−500<x_i,y_i<500-500 < x\_i, y\_i < 500): the coordinates of the polygon vertices, in counterclockwise order. Each coordinate will have exactly 66 digits after the decimal point and will not be exactly an integer.

It is guaranteed that the polygon does not self-intersect, that the vertices are distinct, and that the polygon boundary does not pass through any lattice points.

출력

If there is no solution, print −1-1 and no further output.

Otherwise, print a single integer MM on its own line: the number of semi-integer points in one of the two subsets in a valid partition of P\mathcal{P}. On the next MM lines of output, print the values n_in\_i for the points in that subset, one per line.

If there are multiple valid partitions, you may choose any of them. You may print either of its two subsets, and you may list the subset's n_in\_i values in any order.

예제3

  1. 예제 1

    입력
    4
    -0.950000 -0.850000
    -0.100000 0.999999
    0.111000 0.555000
    -0.200000 1.600000
    
    예상 출력
    3
    0
    -1
    -1
    
  2. 예제 2

    입력
    3
    0.500000 0.700000
    0.100000 0.200000
    0.800000 0.900000
    
    예상 출력
    0
    
  3. 예제 3

    입력
    4
    -360.000001 -24.000001
    -359.999999 -24.000001
    -359.999999 -23.999999
    -360.000001 -23.999999
    
    예상 출력
    2
    -25
    -360