A13576 | Omkar and Password
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!
A password is an array $a$ of $n$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index $i$ such that $1 \leq i < n$ and $a_{i} \neq a_{i+1}$ , delete both $a_i$ and $a_{i+1}$ from the array and put $a_{i}+a_{i+1}$ in their place.
For example, for array $[7, 4, 3, 7]$ you can choose $i = 2$ and the array will become $[7, 4+3, 7] = [7, 7, 7]$ . Note that in this array you can't apply this operation anymore.
Notice that one operation will decrease the size of the password by $1$ . What is the shortest possible length of the password after some number (possibly $0$ ) of operations?
A password is an array $a$ of $n$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index $i$ such that $1 \leq i < n$ and $a_{i} \neq a_{i+1}$ , delete both $a_i$ and $a_{i+1}$ from the array and put $a_{i}+a_{i+1}$ in their place.
For example, for array $[7, 4, 3, 7]$ you can choose $i = 2$ and the array will become $[7, 4+3, 7] = [7, 7, 7]$ . Note that in this array you can't apply this operation anymore.
Notice that one operation will decrease the size of the password by $1$ . What is the shortest possible length of the password after some number (possibly $0$ ) of operations?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 100$ ). Description of the test cases follows.
The first line of each test case contains an integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the length of the password.
The second line of each test case contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ( $1 \leq a_{i} \leq 10^9$ ) — the initial contents of your password.
The sum of $n$ over all test cases will not exceed $2 \cdot 10^5$ .
The first line of each test case contains an integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the length of the password.
The second line of each test case contains $n$ integers $a_{1},a_{2},\dots,a_{n}$ ( $1 \leq a_{i} \leq 10^9$ ) — the initial contents of your password.
The sum of $n$ over all test cases will not exceed $2 \cdot 10^5$ .
输出格式
For each password, print one integer: the shortest possible length of the password after some number of operations.
输入输出样例
输入 #1
2 4 2 1 3 1 2 420 420
输出 #1
1 2
In the first test case, you can do the following to achieve a length of $1$ :
Pick $i=2$ to get $[2, 4, 1]$
Pick $i=1$ to get $[6, 1]$
Pick $i=1$ to get $[7]$
In the second test case, you can't perform any operations because there is no valid $i$ that satisfies the requirements mentioned above.
Pick $i=2$ to get $[2, 4, 1]$
Pick $i=1$ to get $[6, 1]$
Pick $i=1$ to get $[7]$
In the second test case, you can't perform any operations because there is no valid $i$ that satisfies the requirements mentioned above.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted