欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2042B.Game with Colored Marbles
Game with Colored Marbles
Alice and Bob play a game. There are marbles, the -th of them has color . The players take turns; Alice goes first, then Bob, then Alice again, then Bob again, and so on.
During their turn, a player must take one of the remaining marbles and remove it from the game. If there are no marbles left (all marbles have been taken), the game ends.
Alice's score at the end of the game is calculated as follows:
- she receives point for every color such that she has taken at least one marble of that color;
- additionally, she receives point for every color such that she has taken all marbles of that color (of course, only colors present in the game are considered).
For example, suppose there are marbles, their colors are , and the game goes as follows: Alice takes the -st marble, then Bob takes the -rd marble, then Alice takes the -th marble, then Bob takes the -nd marble, and finally, Alice takes the -th marble. Then, Alice receives points: points for having at least one marble for colors , and , and point for having all marbles of color . Note that this strategy is not necessarily optimal for both players.
Alice wants to maximize her score at the end of the game. Bob wants to minimize it. Both players play optimally (i. e. Alice chooses a strategy which allows her to get as many points as possible, and Bob chooses a strategy which minimizes the amount of points Alice can get).
Calculate Alice's score at the end of the game.
Input
The first line contains one integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer () — the number of marbles;
- the second line contains integers () — the colors of the marbles.
Additional constraint on the input: the sum of over all test cases does not exceed .
Output
For each test case, print one integer — Alice's score at the end of the game, assuming that both players play optimally.
Note
In the second test case of the example, the colors of all marbles are distinct, so, no matter how the players act, Alice receives points for having all marbles of two colors, and no marbles of the third color.
In the third test case of the example, the colors of all marbles are the same, so, no matter how the players act, Alice receives point for having at least one (but not all) marble of color .
Samples
3
5
1 3 1 3 4
3
1 2 3
4
4 4 4 4
4
4
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |