Jonah is stuck on a physics problem:
There are three spheres $A$, $B$, and $C$. Each sphere has a charge whose sign is positively charged, negative charged or neutral.
The interaction between two spheres follows these rules:
- Two spheres with the same sign repel each other.
- Two spheres with opposite signs attract each other.
- A charged sphere will attract a neutral sphere, while there is no attraction between two neutral spheres
You are given the results of two experiments. Each result is given in the form
X Y R, where $X,Y \in \{A,B,C\}$ denotes the two distinct spheres, and $R \in \{-1, 0, 1\}$ describes the observed interaction:
- $R = 1$: $X$ and $Y$ attract each other.
- $R = -1$: $X$ and $Y$ repel each other.
- $R = 0$: $X$ and $Y$ do not attract or repel.
Help Jonah by giving any valid assignment of signs to $A$, $B$, and $C$ that is consistent with both experiments.
Input
The input consists of $2$ lines, the $i^{th}$ line contains two uppercase letters $X_i$ and $Y_i$, and an integer $R_i$, separated by spaces.
It is guaranteed that at least one valid assignment exists.
Output
Print three integers $S_A, S_B, S_C \in \{1, 0, -1\}$ separated by spaces, where:
- $1$ indicates a positively charged sphere.
- $-1$ indicates a negatively charged sphere.
- $0$ indicates neutral sphere.
Any valid assignment is accepted.
Subtasks
For all test cases:
- $X_i, Y_i \in \{A,B,C\}$ for $1 \le i \le 2$
- $R_i \in \{-1, 0, 1\}$ for $1 \le i \le 2$
| Subtask | Score | Additional Constraints |
|---|---|---|
| $1$ | $10$ |
$X_1 = $ A, $Y_1 = $ B$X_2 = $ B, $Y_2 = $ C$R_1 = R_2$ |
| $2$ | $15$ |
$X_1 = $ A, $Y_1 = $ B$X_2 = $ B, $Y_2 = $ C$R_i \neq 0$ for $1 \le i \le 2$ |
| $3$ | $20$ |
$X_1 = $ A, $Y_1 = $ B$X_2 = $ B, $Y_2 = $ C |
| $4$ | $15$ | $R_1 = R_2$ |
| $5$ | $15$ | $R_i \neq 0$ for $1 \le i \le 2$ |
| $6$ | $25$ | No Additional Constraints |
Sample Test Cases
| Input | Output | |
|---|---|---|
| A B -1 B C 1 |
1 1 -1 | |
This is one of the possible combinations. Another possible combination: As $B$ and $C$ attract, apart from unlike charges, they could also be $(0,1)$, $(0,-1)$, $(1,0)$ or $(-1,0)$. As $A$ and $B$ repel, they could be both positive or negative. |
||
Scoring: Per Subtask
Authored by s22r42
Appeared in 2026 Mini Comp 6 (Constructive Algorithms & Special Tasks)