10447: USACO 2024 February Contest, Silver Problem 2. Test Tubes
Description
Bessie wants to separate these liquids so that each test tube contains all units of one color of liquid. She has a third empty beaker of infinite capacity to help her in this task. When Bessie makes a "pour", she moves all liquid of color $i$ at the top of one test tube or beaker into another.
Determine the minimum number of pours to separate all the liquid into the two test tubes, and the series of moves needed to do so. It does not matter which test tube ends up with which color, but the beaker must be empty..
There will be $T$ ($1 \leq T \leq 10$) test cases, with a parameter $P$ for each test case.
Suppose the minimum number of pours to separate the liquids into the original tubes is $M$.
- If $P=1$, you will receive credit if you print only $M$.
- If $P=2$, you will receive credit if you print an integer $A$ such that $M \leq A \leq M+5$, followed by $A$ lines that construct a solution with that number of moves. Each line should contain the source and the destination tube ($1$, $2$, or $3$ for the beaker). The source tube must be nonempty before the move and a tube may not be poured into itself.
- If $P=3$, you will receive credit if you print $M$, followed by a valid construction using that number of moves.
Input
It is guaranteed that there will be at least one $1$ and one $2$ across both input strings.
Output
Constraints
- Inputs 2-6: $P = 1$
- Inputs 7-11: $P=2$
- Inputs 12-21: No additional constraints.
Sample 1 Input
6
4 1
1221
2211
4 2
1221
2211
4 3
1221
2211
6 3
222222
111112
4 3
1121
1222
4 2
1121
1222
Sample 1 Output
4
4
1 2
1 3
2 1
3 2
4
1 2
1 3
2 1
3 2
1
2 1
5
2 3
1 2
1 3
1 2
3 1
6
2 3
1 2
1 3
1 2
2 1
3 2
Initial state:
1: 1221 2: 2211 3:After the move "1 2":
1: 122 2: 22111 3:After the move "1 3":
1: 1 2: 22111 3: 22After the move "2 1":
1: 1111 2: 22 3: 22After the move "3 2":
1: 1111 2: 2222 3:
In the last test case, the minimum amount of pours is $5$. However, since $P=2$, the given construction with $6$ moves is valid since it is within $5$ pours from the optimal answer.