CF2242A.Bigrams

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A bigram in a string is a pair of adjacent characters. For example, the string helloello contains 88 bigrams: he, el, ll, lo, oe, el, ll, lo.

Monocarp has cards with letters: c1c_1 cards with the letter a, c2c_2 cards with the letter b, ..., ckc_k cards with the kk-th letter of the Latin alphabet. He wants to make a string from these cards, using each card exactly once. The resulting string must contain at least two equal bigrams. The order of characters in each bigram matters; for example, the string aba does not have two equal bigrams.

Determine whether it is possible to make a string that satisfies these requirements.

字符串中的二元组(bigram)是指一对相邻的字符。例如,字符串 helloello 包含 88 个二元组:he、el、ll、lo、oe、el、ll、lo。

Monocarp 拥有若干张字母卡片:c1c_1 张字母 a 的卡片,c2c_2 张字母 b 的卡片,……,ckc_k 张拉丁字母表中第 kk 个字母的卡片。他希望用这些卡片恰好各使用一次来构造一个字符串。该字符串必须至少包含两个相等的二元组。注意每个二元组中字符的顺序是有意义的;例如,字符串 aba 并不包含两个相等的二元组。

判断是否可能构造出满足上述要求的字符串。

输入格式

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

Each test case consists of two lines:

  • the first line contains one integer kk (1≤k≤101 \le k \le 10);
  • the second line contains kk integers c1,c2,…,ckc_1, c_2, \dots, c_k (1≤ci≤1081 \le c_i \le 10^8), where cic_i is the number of cards with the ii-th letter of the Latin alphabet.

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

每个测试用例由两行组成:

  • 第一行包含一个整数 kk(1≤k≤101 \le k \le 10);
  • 第二行包含 kk 个整数 c1,c2,…,ckc_1, c_2, \dots, c_k(1≤ci≤1081 \le c_i \le 10^8),其中 cic_i 表示拉丁字母表中第 ii 个字母的卡片数量。

输出格式

For each test case, output YES if it is possible to construct a string satisfying the condition, or NO otherwise.

Each letter can be output in any case. For example, yes, Yes, yEs will be recognized as a positive answer.

对于每个测试用例,若能构造出满足条件的字符串,则输出 YES;否则输出 NO。

每个字母可任意使用大小写。例如,yes、Yes、yEs 均被视为肯定回答。

输入输出样例

  • 输入#1

    7
    1
    1
    1
    3
    1
    4
    2
    2 1
    2
    3 2
    3
    1 1 2
    4
    1 1 2 2

    输出#1

    NO
    YES
    YES
    NO
    YES
    NO
    YES

说明/提示

In the first example, you can only make the string a, which contains no bigrams.

In the second example, you can make the string aaa, which contains two bigrams aa.

In the third example, you can make the string aaaa, which contains three bigrams aa.

In the fourth example, you can make the string aab, aba, or baa. None of these strings contains two equal bigrams.

In the fifth example, you can make the string aabab, which contains two bigrams ab.

在第一个例子中,你只能构造字符串 a,其中不包含任何二元组(bigram)。

在第二个例子中,你可以构造字符串 aaa,其中包含两个二元组 aa。

在第三个例子中,你可以构造字符串 aaaa,其中包含三个二元组 aa。

在第四个例子中,你可以构造字符串 aab、aba 或 baa。这些字符串均不包含两个相同的二元组。

在第五个例子中,你可以构造字符串 aabab,其中包含两个二元组 ab。

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

首页