QOJ.ac

QOJ

시간 제한: 1.0 s 메모리 제한: 256 MB 총점: 100 해킹 가능 ✓

#15605. P=NP

통계

Busy Beaver 有一个由字符 PN 组成的字符串 $A$。他可以对 $A$ 进行以下两种操作:

  • 选择一个子串 P 并将其替换为 NP
  • 选择一个子串 NP 并将其替换为 P

Busy Beaver 还有一个目标字符串 $B$。请判断他是否能在进行若干次操作后将 $A$ 转换为 $B$。

(注:长度为 $k$ 的子串是指字符串中 $k$ 个相邻字符组成的连续序列。)

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^4$) —— 测试用例的数量。

每个测试用例的唯一一行包含两个字符串 $A$ 和 $B$ ($1 \le |A|, |B| \le 10^5$),由字符 PN 组成。

所有测试用例的 $|A| + |B|$ 之和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,如果 Busy Beaver 可以使用上述操作将 $A$ 转换为 $B$,则输出 YES,否则输出 NO

你可以输出任意大小写的答案(大写或小写)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 都会被视为肯定的回答。

样例

输入样例 1

7
P NP
PNPN NPPN
PP NP
NPN PPNP
PNPP PPNNNNNNNNNNNNNNNNNNP
PPNNPPNNPP NNPPNNPPNN
NPNNNNNPN PPPN

输出样例 1

YES
YES
NO
NO
YES
NO
NO

说明

在第一个测试用例中,我们可以通过一次操作将 P 转换为 NP

在第二个测试用例中,我们可以进行两次操作:PNPN $\to$ PPN,然后 PPN $\to$ NPPN

在第三个测试用例中,我们可以证明无法通过任意次数的操作将 PP 转换为 NP

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.