Logo
(追記) (追記ここまで)

34918번 - P=NP 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB93494266.667%

문제

Busy Beaver has a string $A$ made up of characters P and N. He can perform two types of operations on $A$:

  • Pick a substring1 P and replace it with NP.
  • Pick a substring NP and replace it with P.

Busy Beaver has a target string $B$. Determine if he can turn $A$ into $B$ after some number of operations.


1A substring of length $k$ is a contiguous sequence of $k$ adjacent characters of a string.

입력

The first line contains a single integer $T$ (1ドル \leq T \leq 10^4$) --- the number of test cases.

The only line of each test case contains the strings $A$ and $B$ (1ドル \leq |A|, |B| \leq 10^5$), consisting of characters P and N.

The sum of $|A|+|B|$ across all test cases does not exceed 2ドル \cdot 10^5$.

출력

For each test case, output YES if Busy Beaver can turn $A$ into $B$ using the operations above, and NO otherwise.

제한

예제 입력 1

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

예제 출력 1

YES
YES
NO
NO
YES
NO
NO

노트

In the first test case, we can perform one operation to turn P into NP.

In the second test case, we can do two operations: PNPN $\to$ PPN and then PPN $\to$ NPPN.

In the third test case, we can show that it is not possible to turn PP into NP using any number of operations.

출처

University > MIT > M(IT)^2 > M(IT)^2 Winter 2025-26 Tournament > Beginner Round 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /