CF1624C.Division by Two and Permutation

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa consisting of nn positive integers. You can perform operations on it.

In one operation you can replace any element of the array aia_i with ⌊ai2⌋\lfloor \frac{a_i}{2} \rfloor, that is, by an integer part of dividing aia_i by 22 (rounding down).

See if you can apply the operation some number of times (possible 00) to make the array aa become a permutation of numbers from 11 to nn —that is, so that it contains all numbers from 11 to nn, each exactly once.

For example, if a=[1,8,25,2]a = [1, 8, 25, 2], n=4n = 4, then the answer is yes. You could do the following:

  1. Replace 88 with ⌊82⌋=4\lfloor \frac{8}{2} \rfloor = 4, then a=[1,4,25,2]a = [1, 4, 25, 2].
  2. Replace 2525 with ⌊252⌋=12\lfloor \frac{25}{2} \rfloor = 12, then a=[1,4,12,2]a = [1, 4, 12, 2].
  3. Replace 1212 with ⌊122⌋=6\lfloor \frac{12}{2} \rfloor = 6, then a=[1,4,6,2]a = [1, 4, 6, 2].
  4. Replace 66 with ⌊62⌋=3\lfloor \frac{6}{2} \rfloor = 3, then a=[1,4,3,2]a = [1, 4, 3, 2].

给你一个由 nn 个正整数组成的数组 aa。你可以对它执行若干次操作。

每次操作中,你可以将数组中的任意一个元素 aia_i 替换为 ⌊ai2⌋\lfloor \frac{a_i}{2} \rfloor,即 aia_i 除以 22 后向下取整(即取整数部分)。

请判断:是否可以通过执行若干次(包括 00 次)上述操作,使得数组 aa 变为 11 到 nn 的一个排列——即数组中恰好包含 11 到 nn 中的每个整数各一次。

例如,若 a=[1,8,25,2]a = [1, 8, 25, 2],n=4n = 4,则答案为“是”。你可以按如下步骤操作:

  1. 将 88 替换为 ⌊82⌋=4\lfloor \frac{8}{2} \rfloor = 4,得到 a=[1,4,25,2]a = [1, 4, 25, 2]。
  2. 将 2525 替换为 ⌊252⌋=12\lfloor \frac{25}{2} \rfloor = 12,得到 a=[1,4,12,2]a = [1, 4, 12, 2]。
  3. 将 1212 替换为 ⌊122⌋=6\lfloor \frac{12}{2} \rfloor = 6,得到 a=[1,4,6,2]a = [1, 4, 6, 2]。
  4. 将 66 替换为 ⌊62⌋=3\lfloor \frac{6}{2} \rfloor = 3,得到 a=[1,4,3,2]a = [1, 4, 3, 2]。

输入格式

The first line of input data contains an integer tt (1≤t≤1041 \le t \le 10^4) —the number of test cases.

Each test case contains exactly two lines. The first one contains an integer nn (1≤n≤501 \le n \le 50), the second one contains integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9).

输入数据的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例恰好包含两行。第一行为一个整数 nn(1≤n≤501 \le n \le 50),第二行为 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

输出格式

For each test case, output on a separate line:

  • YES if you can make the array aa become a permutation of numbers from 11 to nn,
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

对于每个测试用例,在单独的一行上输出:

  • 如果可以将数组 aa 变为 11 到 nn 的一个排列,则输出 YES;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    6
    4
    1 8 25 2
    2
    1 1
    9
    9 8 3 4 2 7 1 5 6
    3
    8 2 1
    4
    24 7 16 7
    5
    22 6 22 4 22

    输出#1

    YES
    NO
    YES
    NO
    NO
    YES

说明/提示

The first test case is explained in the text of the problem statement.

In the second test case, it is not possible to get a permutation.

第一个测试用例在题目描述的正文中已作解释。

在第二个测试用例中,无法得到一个排列。

输入解题思路,AI测评打分。不知道怎么写?

首页