CCC '26 S3 - Common Card Choice
View as PDFCanadian Computing Competition: 2026 Stage 1, Senior #3
There are cards with positive integers written on them. Alice takes
some of the cards, then Bob takes some of the remaining cards. Both need
to take at least one card; Alice is not allowed to take all of the
cards. Then Alice and Bob compute the sum of numbers on the cards that
they have taken. If these sums have a common divisor greater than one,
Alice and Bob get a bag of sweets; otherwise they don't. Given the cards
on the table, determine if it is possible for Alice and Bob to get the
sweets, and if so, how.
To make it even more challenging, in some cases, neither Alice nor Bob knows any of the values on the cards.
Note that an integer is a divisor of an integer
if there is no
remainder when
is divided by
. An integer
is a common
divisor of integers
and
if
is a divisor of both
and
.
Input Specification
The first line of input contains (
).
The second line contains integers,
(
).
The following table shows how the 15 available marks are distributed:
| Marks Awarded | Bounds on |
Bounds on |
|---|---|---|
| 2 marks | ||
| 1 marks | ||
| 1 marks | ||
| 2 marks | ||
| 2 marks | ||
| 7 marks |
Note: For the last subtask, you will be given , but all
card
values will be labelled with
-1, indicating that those card values are
unknown to you. In this last subtask, there will always be a selection
of cards that Alice and Bob can pick to obtain a bag of sweets.
Additional note: The grader is NOT adaptive, that is, the array will be fixed before hand.
Output Specification
On the first line of output, print YES if it is possible to get the
sweets, otherwise, print NO.
If the answer is YES, on the second line of output, produce , the
number of cards that Alice should take, followed by one space, followed
by
, the number of cards that Bob should take. On the third line of
output, print out
space-separated numbers corresponding to the
indices of the cards that Alice should take. On the fourth line of
output, print out
space-separated numbers corresponding to the
indices of the cards that Bob should take. If there are several ways to
select cards, print any of them.
If the input is for the last subtask, output an integer on
the first line, followed by
possible combinations of output as
specified for all other subtasks. That is, each combination will be the
same sequence of three lines as stated above: one line containing
and
; one line containing
indices of cards; and one line
containing
indices of cards. All guesses of indices of cards must be
disjoint: that is, no card index can appear in more than one guess. Your
output will be judged correct if any of the combinations would result in
Alice and Bob obtaining a bag of sweets. Note that you will not receive
any feedback between guesses.
Sample Input 1
7
19 7 11 31 99 13 17
Sample Output 1
YES
3 3
2 3 7
4 6 1
Explanation for Sample Output 1
The sum of Alice's cards is and the sum of Bob's cards is
, and both
and
are divisible by
.
Sample Input 2
3
3 11 17
Sample Output 2
NO
Explanation for Sample Output 2
Notice that ,
, and
have no common divisors, and all
possible sums of two of these numbers (
,
,
) do not have a
common factor with the remaining third number.
Sample Input 3
100000
-1 -1 -1 ...
(The input has been truncated for space. There are a total of
-1s on the second line.)
Sample Output 3
2
1 2
1
3 5
3 2
100 101 102
201 200
Explanation for Sample Output 3
There are a total of two guesses. The first guess consists of indices
and
. The second guess consists of indices
and
.
Note that all sets of indices are disjoint.
Although the output is formatted correctly, the output will receive Wrong answer because the two guesses are not enough for Alice and Bob to obtain a bag of sweets.
Comments
Watch out for sample output 3
I misread this during the contest :-:
this was an incredibly fun problem to do, it only costed my ccc hr
Edit: the non adaptive array part is really helpful now that ccc is over