Connection Status:
Competition Arena > TheSwapsDivTwo
SRM 575 · 2012-12-13 · by Vasyl[alphacom] · Brute Force
Class Name: TheSwapsDivTwo
Return Type: int
Method Name: find
Arg Types: (vector<int>)
Problem Statement

Problem Statement

John has a sequence of integers. Brus is going to choose two different positions in John's sequence and swap the elements at those positions. (The two swapped elements may have the same value.) Return the number of different sequences Brus can obtain after he makes the swap.

Constraints

  • sequence will contain between 2 and 47 elements, inclusive.
  • Each element of sequence will be between 1 and 47, inclusive.
Examples
0)
{4, 7, 4}
Returns: 3

If Brus swaps elements 0 and 1 (0-based indices), the sequence will change to {7, 4, 4}. If he swaps elements 1 and 2 instead, the sequence will change to {4, 4, 7}. Finally, if the swaps elements 0 and 2, the sequence will remain {4, 7, 4}. These three outcomes are all distinct.

1)
{1, 47}
Returns: 1

Brus has to swap the only two elements, producing the sequence {47, 1}. Note that Brus has to make the swap, he cannot keep the original sequence.

2)
{9, 9, 9, 9}
Returns: 1

Regardless of which two elements Brus swaps, the resulting sequence will always be {9, 9, 9, 9}.

3)
{22, 16, 36, 35, 14, 9, 33, 6, 28, 12, 18, 14, 47, 46, 29, 22, 14, 17, 4, 15, 28, 6, 39, 24, 47, 37}
Returns: 319
4)
{7, 2, 21, 27, 5, 8, 14, 4, 42, 1, 12, 12, 24, 19, 31, 17, 19, 34, 13, 16, 30, 10, 20, 19, 30, 1, 47, 10, 19, 38, 30, 31, 33, 23, 46, 44, 8, 31, 26, 36, 1, 1, 12, 39, 9}
Returns: 968

Submissions are judged against all 92 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheSwapsDivTwo with a public method int find(vector<int> sequence) · 92 test cases · 2 s / 256 MB per case

Submitting as anonymous