Codeforces Round 994 (Div. 2)
B
pspspsps
Codeforces
1300
原题
← AC →
翻译中…

Cats are attracted to pspspsps, but Evirir, being a dignified dragon, is only attracted to pspspsps with oddly specific requirements...

翻译中…

Given a string $s = s_1s_2\ldots s_n$ of length $n$ consisting of characters p, s, and . (dot), determine whether a permutation$^{\text{∗}}$ $p$ of length $n$ exists, such that for all integers $i$ ($1 \le i \le n$):

翻译中…
  • If $s_i$ is p, then $[p_1, p_2, \ldots, p_i]$ forms a permutation (of length $i$);
  • If $s_i$ is s, then $[p_i, p_{i+1}, \ldots, p_{n}]$ forms a permutation (of length $n-i+1$);
  • If $s_i$ is ., then there is no additional restriction.
翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 500$), the length of $s$.

翻译中…

The second line of each test case contains a string $s$ of length $n$ that consists of the characters p, s, and ..

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.

翻译中…

Output

翻译中…

For each test case, output YES or NO on a line. Output YES if there is such a permutation and NO otherwise.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

For the first test case, one permutation that works is $p = [3, 4, 1, 2]$. The restrictions are as follows:

翻译中…
  • $s_1 =$ s: $[p_1, p_2, p_3, p_4] = [3, 4, 1, 2]$ forms a permutation.
  • $s_2 =$ .: No additional restriction.
  • $s_3 =$ s: $[p_3, p_4] = [1, 2]$ forms a permutation.
  • $s_4 =$ p: $[p_1, p_2, p_3, p_4] = [3, 4, 1, 2]$ forms a permutation.
翻译中…

For the second test case, it can be proven that there is no permutation that satisfies all restrictions.

翻译中…

For the third test case, one permutation that satisfies the constraints is $p = [1, 2, 3, 4, 5]$.

翻译中…

样例

Input #1
9
4
s.sp
6
pss..s
5
ppppp
2
sp
4
.sp.
8
psss....
1
.
8
pspspsps
20
....................
Output #1
YES
NO
YES
YES
NO
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2049B
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
图匹配
模拟

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