TaroCards
SRM 613 · 2013-12-22 · by Witaliy
Problem Statement
Cat Taro has N cards.
Exactly two integers are written on each card.
You are given two
It is known that for each x from 1 to N, inclusive, there is exactly one card with the first integer equal to x. In other words, all elements of first represent a permutation of integers from 1 to N, inclusive. On the other hand, second may contain duplicates, but all elements of second are only between 1 and 10, inclusive.
You are also given an
Constraints
- first will contain between 1 and 50 elements, inclusive.
- first and second will contain the same number of elements.
- first will represent a permutation of integers between 1 and N, inclusive, where N is the number of elements in first.
- Each element of second will be between 1 and 10, inclusive.
- K will be between 1 and 2N, inclusive, where N is the number of elements in first.
{1, 2}
{2, 3}
2
Returns: 3
In this case, there are four subsets of cards: None of the cards. The number of different integers is 0. Only the first card. The number of different integers is 2. Only the second card. The number of different integers is 2. Both the first and the second card. The number of different integers is 3. However, the last subset has too many different integers. Thus, the answer is 3.
{3, 1, 2}
{1, 1, 1}
3
Returns: 8
{4, 2, 1, 3}
{1, 2, 3, 4}
5
Returns: 16
{1, 2, 3, 4, 5, 6, 7}
{2, 1, 10, 9, 3, 2, 2}
3
Returns: 17
{1}
{2}
1
Returns: 1
Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TaroCards with a public method long long getNumber(vector<int> first, vector<int> second, int K) · 70 test cases · 2 s / 256 MB per case