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

30531번 - Impartial Strings 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB40151356.522%

문제

Alice builds machines that generates strings. Alice's machines each consist of $N$ states, numbered from 1ドル$ to $N,ドル and a set of directed edges between these states, each labelled with a character from a fixed set. A subset of the states are "final" states. The machine generates strings by starting at state 1ドル,ドル following a path that terminates at a final state, and concatenating the characters of the edge labels together in the order that the edges are traversed. The path is allowed to visit the same state more than once and can traverse the same edge more than once. The path can pass through final states before eventually terminating at a final state. Self loops are allowed and having two or more edges to and/or from the same state labelled with the same letter is also allowed.

Bob has a favorite string $S$. Carol has a favorite string $T$. Alice wonders if she can build a machine that can generate exactly the strings that have an equal number of occurrences of $S$ and $T$ as substrings. That is, the machine should generate every string that has an equal number of occurrences of $S$ and $T$ as substrings and it should not generate any strings that do not satisfy this property. Occurrences may overlap. For example, the string banana has two occurrences of the substring ana. Help Alice determine if it is possible to complete the task for Bob and Carol's favorite strings.

Figure H.1: Example machine for the first case in the sample input.

Figure H.1 gives an example machine for the first case in the sample input. The square states represent the final states.

입력

The first line of input contains a single positive integer $K$ $(1\leq K \leq 50),ドル the number of test cases. This is followed by $K$ lines each containing three strings $A,ドル $S,ドル $T$. The first string, $A,ドル is the fixed set of characters used in the machine. The characters in $A$ are distinct lowercase english letters. The second string, $S,ドル is Bob's favorite string. The third string, $T,ドル is Carol's favorite string. The lengths of $S$ and $T$ satisfy 1ドル\leq |S|,|T|\leq 500$. It is guaranteed that the distinct characters in $S$ and $T$ are a subset of those in $A$.

출력

Output one line for each test case. Output 1ドル$ if Alice can build a machine as described. Otherwise, output 0ドル$.

제한

예제 입력 1

3
ab ab ba
abc ab ba
cz cczz zzcc

예제 출력 1

1
0
0

힌트

출처

ICPC > Regionals > North America > East Central North America Regional > 2023-2024 East Central NA Regional Contest H번

  • 문제를 만든 사람: Finn Lidbetter
(追記) (追記ここまで)

출처

대학교 대회

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

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