PerfectSequences2
Member SRM 505 · 2010-11-01 · by ivan_metelsky
Problem Statement
You are given a
Constraints
- seq will contain between 1 and 50 elements, inclusive.
- Each element of seq will be between -1,000,000,000 and 1,000,000,000, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
{-1000000000}
Returns: 0
Any sequence consisting of 1 integer is perfect, so no additional moves are needed.
{-2}
Returns: 0
{-1}
Returns: 0
{0}
Returns: 0
{1}
Returns: 0
{-1,1}
Returns: 2
There are 2 perfect sequences containing two elements: {0,0} and {2,2}. In order to obtain {0,0} from {-1,1} you need 2 moves, in order to obtain {2,2} you need 4 moves.
{4,3}
Returns: 3
This time it is better to obtain {2,2}.
{17,95,-79}
Returns: 33
Here the best solution is to transform seq into {0,95,-95}.
{10,9,8}
Returns: 21
Decrease each element by 7 to obtain {3,2,1}.
Submissions are judged against all 332 archived test cases, of which 9 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PerfectSequences2 with a public method long long minimumMoves(vector<int> seq) · 332 test cases · 2 s / 256 MB per case