CF1392A.Omkar and Password
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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≤i<n and ai=ai+1, delete both ai and ai+1 from the array and put ai+ai+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?
奥姆卡尔大人允许你进入神圣的奥姆卡尔教堂!为了测试你的资格,奥姆卡尔给了你一个密码,你必须解读它!
密码是一个由 n 个正整数组成的数组 a。你需要对数组执行如下操作:任选两个相邻且不相等的数,并将它们替换为它们的和。形式化地说,选择一个下标 i,满足 1≤i<n 且 ai=ai+1,从数组中删除 ai 和 ai+1,并在原位置插入 ai+ai+1。
例如,对于数组 [7,4,3,7],你可以选择 i=2,数组将变为 [7,4+3,7]=[7,7,7]。注意,在该数组中已无法再执行此操作。
注意,每次操作会使密码长度减少 1。在执行若干次(可能为 0 次)操作后,密码可能达到的最短长度是多少?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). Description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤2⋅105) — the length of the password.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the initial contents of your password.
The sum of n over all test cases will not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 密码的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 密码的初始内容。
所有测试用例中 n 的总和不超过 2⋅105。
输出格式
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.
在第一个测试用例中,你可以执行以下操作以得到长度为 1 的数组:
选择 i=2,得到 [2,4,1];
选择 i=1,得到 [6,1];
选择 i=1,得到 [7]。
在第二个测试用例中,你无法执行任何操作,因为不存在满足上述要求的合法下标 i。
输入解题思路,AI测评打分。不知道怎么写?