311191: CF1948B. Array Fix

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Array Fixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given an integer array $a$ of length $n$.

You can perform the following operation any number of times (possibly zero): take any element of the array $a$, which is at least $10$, delete it, and instead insert the digits that element consisted of in the same position, in order they appear in that element.

For example:

  • if we apply this operation to the $3$-rd element of the array $[12, 3, 45, 67]$, then the array becomes $[12, 3, 4, 5, 67]$.
  • if we apply this operation to the $2$-nd element of the array $[2, 10]$, then the array becomes $[2, 1, 0]$.

Your task is to determine whether it is possible to make $a$ sorted in non-descending order using the aforementioned operation any number of times (possibly zero). In other words, you have to determine if it is possible to transform the array $a$ in such a way that $a_1 \le a_2 \le \dots \le a_k$, where $k$ is the current length of the array $a$.

Input

The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases.

Each test case consists of two lines:

  • the first line contains a single integer $n$ ($2 \le n \le 50$).
  • the second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 99$).
Output

For each test case, print YES if it is possible to make $a$ sorted in non-decreasing order using the aforementioned operation; otherwise, print NO.

You can print each letter in any case. For example, yes, Yes, YeS will all be recognized as a positive answer.

ExampleInput
3
4
12 3 45 67
3
12 28 5
2
0 0
Output
YES
NO
YES
Note

In the first example, you can split the first element, then the array becomes $[1, 2, 3, 45, 67]$.

In the second example, there is no way to get a sorted array.

In the third example, the array is already sorted.

Output

题目大意:
给定一个长度为n的整数数组a。你可以进行任意次数(可能为零)的以下操作:选择数组a中至少为10的任意元素,删除它,并在相同的位置插入该元素的各个数字,顺序与该元素中出现的顺序相同。目标是通过上述操作(任意次数,可能为零)判断是否可能使数组a按非降序排列。即判断是否可以通过变换使数组a满足a1 ≤ a2 ≤ … ≤ ak,其中k是当前数组a的长度。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1 ≤ t ≤ 10^3)——测试用例的数量。
- 每个测试用例包含两行:
- 第一行包含一个整数n(2 ≤ n ≤ 50)。
- 第二行包含n个整数a1, a2, …, an(0 ≤ ai ≤ 99)。

输出:
- 对于每个测试用例,如果可以通过上述操作使数组a按非降序排列,则打印YES;否则,打印NO。
- 每个字母的打印大小写均可。例如,yes、Yes、YeS都将被识别为肯定答案。题目大意: 给定一个长度为n的整数数组a。你可以进行任意次数(可能为零)的以下操作:选择数组a中至少为10的任意元素,删除它,并在相同的位置插入该元素的各个数字,顺序与该元素中出现的顺序相同。目标是通过上述操作(任意次数,可能为零)判断是否可能使数组a按非降序排列。即判断是否可以通过变换使数组a满足a1 ≤ a2 ≤ … ≤ ak,其中k是当前数组a的长度。 输入输出数据格式: 输入: - 第一行包含一个整数t(1 ≤ t ≤ 10^3)——测试用例的数量。 - 每个测试用例包含两行: - 第一行包含一个整数n(2 ≤ n ≤ 50)。 - 第二行包含n个整数a1, a2, …, an(0 ≤ ai ≤ 99)。 输出: - 对于每个测试用例,如果可以通过上述操作使数组a按非降序排列,则打印YES;否则,打印NO。 - 每个字母的打印大小写均可。例如,yes、Yes、YeS都将被识别为肯定答案。

加入题单

上一题 下一题 算法标签: