#P4263. [Code+#3] 投票统计
[Code+#3] 投票统计
Description
To review the problem-setting work over the past period, Captain Wang organized a "My Favorite Problem" selection and invited all contestants to vote for the problems.
Specifically, each problem has a positive integer as its ID. There are contestants voting; each contestant votes for exactly one problem, and the -th contestant votes for the problem with ID .
Since there are many voters, Captain Wang asks you to help tally the votes. You need to find the number of problems that received the most votes and their IDs, and list these IDs in ascending order. However, there is one exception: if all problems that received at least one vote have the same number of votes, then Captain Wang considers the event unsuccessful, and you should output -1.
Input Format
The first line contains a positive integer , the number of testdata groups. There is no blank line between groups.
The next lines describe each group in order:
Each group contains two lines. The first line contains a positive integer , the number of contestants participating. The second line contains space-separated positive integers , where the -th number is the ID of the problem voted for by the -th contestant.
Output Format
The output consists of groups, with no blank lines between groups. For each group:
If the exception described in the statement does not occur, output two lines for this group. On the first line, output a positive integer , the number of problems that received the most votes. On the second line, output positive integers in ascending order, which are the IDs of these problems.
If the exception occurs, output one line for this group: output -1.
3
10
2 6 1 2 1 1 2 6 7 1
10
10 3 6 6 3 10 6 6 6 2
10
8 8 10 10 10 10 8 5 8 8
1
1
1
6
1
8
3
10
1 4 3 1 8 8 7 2 8 7
10
1 10 9 1 3 2 9 9 2 1
10
4 1 5 4 1 9 5 5 4 1
1
8
2
1 9
3
1 4 5
3
10
3 3 10 8 8 3 10 8 10 3
10
2 2 8 6 8 4 2 4 4 8
10
6 2 5 6 7 5 7 10 2 10
1
3
3
2 4 8
-1
Hint
| Test point ID | Range of | Range of | Special notes |
|---|---|---|---|
| 1 | The problem with the most votes is unique | ||
| 2 | Same as above | Same as above | Same as above |
| 3 | |||
| 4 | The exception will not occur | ||
| 5 | Same as above | Same as above | |
| 6 | |||
| 7 | None | ||
| 8 | Same as above | Same as above | |
| 9 | |||
| 10 | Same as above | ||
| 11 | The problem with the most votes is unique | ||
| 12 | Same as above | Same as above | Same as above |
| 13 | |||
| 14 | The exception will not occur | ||
| 15 | Same as above | Same as above | |
| 16 | |||
| 17 | None | ||
| 18 | Same as above | Same as above | |
| 19 | |||
| 20 | Same as above |
Credit: https://www.luogu.org/discuss/show?postid=35727.
Translated by ChatGPT 5
京公网安备 11011102002149号