欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2032A.Circuit
Circuit
Alice has just crafted a circuit with lights and switches. Each component (a light or a switch) has two states: on or off. The lights and switches are arranged in a way that:
- Each light is connected to exactly two switches.
- Each switch is connected to exactly one light. It's unknown which light each switch is connected to.
- When all switches are off, all lights are also off.
- If a switch is toggled (from on to off, or vice versa), the state of the light connected to it will also toggle.
Alice brings the circuit, which shows only the states of the switches, to her sister Iris and gives her a riddle: what is the minimum and maximum number of lights that can be turned on?
Knowing her little sister's antics too well, Iris takes no more than a second to give Alice a correct answer. Can you do the same?
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the number of lights in the circuit.
The second line of each test case contains integers () — the states of the switches in the circuit. means the -th switch is off, and means the -th switch is on.
Output
For each test case, output two integers — the minimum and maximum number of lights, respectively, that can be turned on.
Note
In the first test case, there is only one light in the circuit, and no switch is on, so the light is certainly off.
In the second test case, there is only one light in the circuit, but one switch connected to it is on, so the light is on.
In the third test case, there is only one light in the circuit, and both switches are on, so the light is off as it was toggled twice.
In the fourth test case, to have no lights on, the switches can be arranged in this way:
- Switch and switch are connected to light . Since both switches are off, light is also off.
- Switch and switch are connected to light . Since both switches are off, light is also off.
- Switch and switch are connected to light . Both switches are on, so light is toggled twice from its initial off state, and thus also stays off.
And to have lights on, the switches can be arranged in this way:
- Switch and switch are connected to light . Since both switches are off, light is also off.
- Switch and switch are connected to light . Since switch is on and switch is off, light is toggled once from its initial off state, so it is on.
- Switch and switch are connected to light . Since switch is on and switch is off, light is toggled once from its initial off state, so it is on.
Samples
5
1
0 0
1
0 1
1
1 1
3
0 0 1 0 1 0
3
0 1 1 1 0 0
0 0
1 1
0 0
0 2
1 3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |