CF1624C.Division by Two and Permutation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n positive integers. You can perform operations on it.
In one operation you can replace any element of the array ai with ⌊2ai⌋ , that is, by an integer part of dividing ai by 2 (rounding down).
See if you can apply the operation some number of times (possible 0 ) to make the array a become a permutation of numbers from 1 to n —that is, so that it contains all numbers from 1 to n , each exactly once.
For example, if a=[1,8,25,2] , n=4 , then the answer is yes. You could do the following:
- Replace 8 with ⌊28⌋=4 , then a=[1,4,25,2] .
- Replace 25 with ⌊225⌋=12 , then a=[1,4,12,2] .
- Replace 12 with ⌊212⌋=6 , then a=[1,4,6,2] .
- Replace 6 with ⌊26⌋=3 , then a=[1,4,3,2] .
输入格式
The first line of input data contains an integer t ( 1≤t≤104 ) —the number of test cases.
Each test case contains exactly two lines. The first one contains an integer n ( 1≤n≤50 ), the second one contains integers a1,a2,…,an ( 1≤ai≤109 ).
输出格式
For each test case, output on a separate line:
- YES if you can make the array a become a permutation of numbers from 1 to n ,
- 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).
输入输出样例
输入#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.