BinaryFlips
SRM 443 · 2009-06-23 · by gojira_tc
Problem Statement
Constraints
- A will be between 0 and 100,000, inclusive.
- B will be between 0 and 100,000, inclusive.
- K will be between 1 and 100,000, inclusive.
3 0 3 Returns: 1
You initially have 3 zeros and 0 ones, and you must flip 3 numbers in each move. Your only possible move is to flip every number. After the first move, you end up with all ones and win the game.
4 0 3 Returns: 4
This is similar to the previous example, but this time, you have 4 zeros. Here's one minimal sequence of moves that will lead to a win: 0. 0000 (the initial state) 1. 1110 (first three numbers flipped) 2. 1001 (last three numbers flipped) 3. 0100 (first, second and fourth numbers flipped) 4. 1111 (first, third and fourth numbers flipped)
4 1 3 Returns: 2
3 2 5 Returns: -1
100000 100000 578 Returns: 174
Submissions are judged against all 283 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BinaryFlips with a public method int minimalMoves(int A, int B, int K) · 283 test cases · 2 s / 256 MB per case