CF1499B.Binary Removals

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string ss , consisting only of characters '0' or '1'. Let s|s| be the length of ss .

You are asked to choose some integer kk ( k>0k > 0 ) and find a sequence aa of length kk such that:

  • 1a1<a2<<aks1 \le a_1 < a_2 < \dots < a_k \le |s| ;
  • ai1+1<aia_{i-1} + 1 < a_i for all ii from 22 to kk .

The characters at positions a1,a2,,aka_1, a_2, \dots, a_k are removed, the remaining characters are concatenated without changing the order. So, in other words, the positions in the sequence aa should not be adjacent.

Let the resulting string be ss' . ss' is called sorted if for all ii from 22 to s|s'| si1sis'_{i-1} \le s'_i .

Does there exist such a sequence aa that the resulting string ss' is sorted?

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of testcases.

Then the descriptions of tt testcases follow.

The only line of each testcase contains a string ss ( 2s1002 \le |s| \le 100 ). Each character is either '0' or '1'.

输出格式

For each testcase print "YES" if there exists a sequence aa such that removing the characters at positions a1,a2,,aka_1, a_2, \dots, a_k and concatenating the parts without changing the order produces a sorted string.

Otherwise, print "NO".

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

输入输出样例

  • 输入#1

    5
    10101011011
    0000
    11111
    110
    1100

    输出#1

    YES
    YES
    YES
    YES
    NO

说明/提示

In the first testcase you can choose a sequence a=[1,3,6,9]a=[1,3,6,9] . Removing the underlined letters from "10101011011" will produce a string "0011111", which is sorted.

In the second and the third testcases the sequences are already sorted.

In the fourth testcase you can choose a sequence a=[3]a=[3] . s=s'= "11", which is sorted.

In the fifth testcase there is no way to choose a sequence aa such that ss' is sorted.

首页