10448: USACO 2024 February Contest, Silver Problem 3. Moorbles
Description
After some amount of turns in the game, Elsie has $N$ $(1 \leq N \leq 10^9)$ marbles. She thinks it is hard to win, but she is playing to not lose. After being around Bessie enough, Elsie has a good read on Bessie's habits and recognizes that on turn $i$, there are only $K$ $(1 \leq K \leq 4)$ different amounts of marbles that Bessie may put out. There are only $M$ $(1 \leq M \leq 3 \cdot 10^5)$ turns before Bessie gets bored and stops playing. Can you identify a lexicographically minimum turn sequence such that Elsie will not lose, regardless of how Bessie plays?
Input
- First, one line containing three integers $N$, $M$, and $K$, representing the number of marbles Elsie has, the number of turns, and the number of potential moves Bessie can make respectively.
- Then, $M$ lines where line $i$ contains $K$ distinct space separated integers $a_{i,1} \; a_{i,2} \ldots a_{i,K}$ ($1 \leq a_{i, j} \leq 10^3$) representing the possible amounts of marbles that Bessie might play on turn $i$.
Output
Note: "Even" is lexicographically smaller than "Odd".
Constraints
- Input 3: $M \leq 16$.
- Inputs 4-6: $M \leq 1000$.
- Inputs 7-12: No further constraints.
Sample 1 Input
2
10 3 2
2 5
1 3
1 3
10 3 3
2 7 5
8 3 4
2 5 6
Sample 1 Output
Even Even Odd
-1
If Elsie instead plays the correct move sequence "Even Even Odd", then if Bessie plays the same way, at the end when she plays $3$, Elsie will gain those $3$ marbles, increasing her number of marbles to $5$. It can further be shown that Bessie cannot play in a different way to take all of Elsie's marbles given that Elsie plays "Even Even Odd".
In the second case, it can be shown that for any move sequence that Elsie could choose, Bessie can play in a way to take all of Elsie's marbles.
Sample 2 Input
1
20 8 2
3 5
3 5
3 5
3 5
3 5
3 5
3 5
3 5
Sample 2 Output
Even Even Even Odd Even Odd Even Odd