| 2025 ICPC, Chula Selection Contest |
|---|
| Finished |
In a vast and mysterious world lies an infinite two-dimensional grid. Each location in this grid is identified by integer coordinates $$$(x, y)$$$. You have been informed that a demon is hiding somewhere in this grid, and your mission is to find the exact position of the demon before it disappears forever.
You have received $$$n$$$ clues from ancient observers who tried to track the demon's movement. Each clue is described by three integers $$$(x_i, y_i, d_i)$$$, meaning that the demon is at a Cartesian distance of $$$\sqrt{d_i}$$$ from the point $$$(x_i, y_i)$$$. However, the demon is a master of illusions, so not all clues can be trusted. The demon has created shadow replicas of itself at certain locations, causing some clues to be either real or fake followed by these conditions: if a clue is real, the demon's actual position must exactly match the distance indicated by that clue's coordinates and distance value; if a clue is fake, the demon's position must not match that distance.
Unfortunately, you do not know which clues are real and which are fake. To ensure that the demon can be captured, you have to find the maximum number of real clues that allows you to locate the demon's position without needing to know in advance which clues are real.
Formally, let $$$c_i$$$ represent clue $$$(x_i,y_i,d_i)$$$. Suppose the demon is located at position $$$o = (o_x,o_y)$$$, the reality of a clue is defined as follows:
The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$
The next $$$n$$$ lines contain clues. Each contains three integers $$$x_i, y_i, d_i$$$ $$$(-10^5 \leq x_i, y_i \leq 10^5, 1 \leq d_i\leq 10^5)$$$
It is guaranteed that the demon's coordinates must be integers.
If no solution exists, print -1.
Otherwise, print two lines. On the first line, print the maximum number $$$k$$$ of real clues that satisfy the conditions. On the second line, print two space-separated integers representing the demon's position: $$$o_x$$$ and $$$o_y$$$.
415 0 921 0 92 0 138 0 13
2 18 0
80 0 250 10 255 5 2520 0 2520 10 2525 5 2510 -10 1618 -10 16
-1
80 0 251 0 162 0 910 0 916 0 9-12 0 25-11 0 16-10 0 9
2 13 0
In the first test case:
if $$$k = 4:$$$ The only possible set includes all four clues, and this set is contradictory.
if $$$k = 3:$$$ There are four possible sets of three clues, and all of them are contradictory.
if $$$k = 2:$$$
if $$$k = 1:$$$ Choosing any single clue is ambiguous, resulting in multiple solutions.
Therefore, the maximum number of clues that satisfy the conditions is $$$2$$$, and the corresponding demon position is $$$(18, 0)$$$.
In the second test case:
If $$$k \ge 4$$$: It is easy to see that there is no way to choose $$$k$$$ clues such that they determine a position.
if $$$k = 3$$$: There are two possible ways to select three clues that determines a position
if $$$k = 2$$$: There are five possible ways to select two clues that determine a position:
if $$$k = 1$$$: Choosing any single clue is ambiguous, resulting in multiple solutions.
Therefore, the result is $$$-1$$$.
| Name |
|---|


