CF1499B.Binary Removals

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

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 \gt 0) and find a sequence aa of length kk such that:

  • 1≤a1<a2<⋯<ak≤∣s∣1 \le a_1 \lt a_2 \lt \dots \lt a_k \le |s|;
  • ai−1+1<aia_{i-1} + 1 \lt 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 s′s'. s′s' is called sorted if for all ii from 22 to ∣s′∣|s'| si−1′≤si′s'_{i-1} \le s'_i.

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

给你一个字符串 ss,它仅由字符 '0' 或 '1' 组成。令 ∣s∣|s| 表示 ss 的长度。

你需要选择某个整数 kk(其中 k>0k > 0),并找出一个长度为 kk 的序列 aa,满足:

  • 1≤a1<a2<⋯<ak≤∣s∣1 \le a_1 < a_2 < \dots < a_k \le |s|;
  • 对所有 ii 从 22 到 kk,均有 ai−1+1<aia_{i-1} + 1 < a_i。

删除位于位置 a1,a2,…,aka_1, a_2, \dots, a_k 上的字符,将剩余字符按原有顺序拼接起来,得到字符串 s′s'。换言之,序列 aa 中的下标彼此不能相邻。

若对所有 ii 从 22 到 ∣s′∣|s'| 均有 si−1′≤si′s'_{i-1} \le s'_i,则称 s′s' 是有序的(sorted)。

是否存在这样的序列 aa,使得最终得到的字符串 s′s' 是有序的?

输入格式

The first line contains a single integer tt (1≤t≤10001 \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 (2≤∣s∣≤1002 \le |s| \le 100). Each character is either '0' or '1'.

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

接下来是 tt 个测试用例的描述。

每个测试用例仅有一行,包含一个字符串 ss(2≤∣s∣≤1002 \le |s| \le 100),其中每个字符均为 '0' 或 '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).

对于每个测试用例,如果存在一个序列 aa,使得删除位置为 a1,a2,…,aka_1, a_2, \dots, a_k 的字符,并将剩余部分按原顺序拼接后得到一个升序字符串,则输出 "YES";
否则输出 "NO"。

你可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均被识别为肯定回答)。

输入输出样例

  • 输入#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 s′s' is sorted.

在第一个测试用例中,你可以选择序列 a=[1,3,6,9]a=[1,3,6,9]。从字符串 "10101011011" 中删除下划线标出的位置上的字符,将得到字符串 "0011111",该字符串是已排序的。

在第二个和第三个测试用例中,序列本身已经是排序好的。

在第四个测试用例中,你可以选择序列 a=[3]a=[3],此时 s′=s'= "11",该字符串是已排序的。

在第五个测试用例中,不存在任何序列 aa 能使得 s′s' 是已排序的。

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

首页