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

28320번 - Flip it and Stick it 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB32121237.500%

문제

Finn is playing a game of "Flip it and Stick it" which is abbreviated as FiSi. FiSi is a one-player game played on two strings, $S$ and $T,ドル of 0s and 1s. Finn is allowed to make moves of the following form:

  • Select a substring of $S$ and reverse it, gluing the pieces of the string back together in their original order to form the new string $S$.

For example, Finn may take the string $S =$ 101100, take the substring 011 starting at index 2ドル$ (assuming 1ドル$-based string indexing), and create the string $S =$ 111000 in one move. Finn wins the game if $S$ does not contain $T$ as a substring. Your task is to help Finn determine the length of the shortest winning sequence of moves or tell him that the game cannot be won.

입력

The first line of input contains the string $S$ $(1 \le |S| \le 200,000円)$.

The second line of input contains the string $T$ $(1 \le |T| \le 3)$.

In the table below, $T_1$ is the first bit in $T,ドル $T_2$ is the second bit in $T,ドル and $T_3$ is the third bit in $T,ドル when reading from left-to-right.

출력

Output the minimum number of moves needed or -1 if it is impossible to win the game.

제한

예제 입력 1

100110
10

예제 출력 1

2

Finn starts with the string 100110. He cannot avoid 10 as a substring in one move, but he can in two moves.

For example, his first move could be to reverse the substring from index 4ドル$ to index 6ドル$ (110) to get 100011. Then, his second move can be to reverse the substring from index 1ドル$ to index 4ドル$ (1000) to get 000111, which does not have 10 as a substring.

예제 입력 2

000
00

예제 출력 2

-1

No matter how many moves Finn makes, the string $S$ will always contain $T$ as a substring.

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2023 > CCO 2023 4번

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

출처

대학교 대회

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

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