AtCoder Regular Contest 163
A
Divide String
AtCoder
⌀ 373
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given a string $S$ of length $N$ consisting of lowercase English letters. Determine whether it is possible to divide $S$ into two or more consecutive substrings so that they are strictly increasing in lexicographical order.

翻译中…

To be precise, determine whether there is a sequence of strings $t=(t_1,t_2,\dots,t_k)$ that satisfies all of the following conditions.

翻译中…
  • The length of the sequence $k$ is at least $2$.
  • $t_i$ is not empty. ($1 \le i \le k$)
  • Concatenating $t_1,t_2,\dots,t_k$ in this order results in $S$.
  • $t_i$ is lexicographically smaller than $t_{i+1}$ for every integer $i$ such that $1 \le i < k$.
翻译中…

You are given $T$ test cases. Find the answer for each of them.

翻译中…

What is lexicographical order? A string $S = S_1S_2\ldots S_{|S|}$ is said to be lexicographically smaller than a string $T = T_1T_2\ldots T_{|T|}$ if either 1. or 2. below holds. Here, $|S|$ and $|T|$ represent the lengths of $S$ and $T$, respectively. $|S| \lt |T|$ and $S_1S_2\ldots S_{|S|} = T_1T_2\ldots T_{|S|}$. There is an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that both of the following hold. $S_1S_2\ldots S_{i-1} = T_1T_2\ldots T_{i-1}$. The character $S_i$ comes before $T_i$ in alphabetical order.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 2000$
  • $2 \le N \le 2000$
  • $S$ is a string of length $N$ consisting of lowercase English letters.
  • The sum of $N$ over all test cases in a single input does not exceed $2000$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

翻译中…

Here, $\mathrm{case}_i$ represents the $i$-th test case. Each test case is given in the following format:

翻译中…

N
S

翻译中…

Output

翻译中…

Print $T$ lines.

翻译中…

The $i$-th line $(1 \le i \le T)$ should contain Yes if it is possible to divide $S$ in the $i$-th test case into substrings that satisfy the conditions, and No otherwise.

翻译中…

样例

Input #1
5
4
abac
3
cac
2
ab
12
abababababab
5
edcba
Output #1
Yes
No
Yes
Yes
No
For the first test case, you can divide $S$ into `a`, `ba`, `c`. For the second test case, there is no way to divide $S$ into substrings so that they are strictly increasing in lexicographical order.
题目信息
题号
arc163_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。