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

23485번 - Median Replace Hard 다국어

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

문제

Do you know this problem: https://atcoder.jp/contests/agc022/tasks/agc022_e? We generalize it a bit.

You got a binary string $P = P_0P_1P_2P_3P_4P_5P_6P_7$ of length 8ドル$.

You think a binary string $X$ of odd length $N$ is beautiful if it is possible to apply the following operation $\frac{N-1}{2}$ times so that the only character of the resulting string is '1' :

  • Choose three consecutive bits of $X,ドル $(X_i,X_{i + 1},X_{i + 2}),ドル and replace them by the $(X_i + 2X_{i + 1} + 4X_{i + 2})$-th bit of $P$.

Note that, when $P = 00010111,ドル this definition is the same as the original AGC problem.

You have a string $S$ consisting of characters '0', '1', and '?'. You want to know the number of ways to replace the question marks with '1' or '0' so that the resulting string is beautiful, modulo 10ドル^9 + 7$.

Note that there are $T$ tests in one input file.

입력

Input is given from Standard Input in the following format:

$T$

$P$ $S$

$P$ $S$

$\vdots$

$P$ $S$

출력

For each case, print the answer in a line.

제한

  • 1ドル \leq T \leq 256$
  • $|P|=8$
  • 1ドル \leq |S|$ and $\sum {|S|} \leq 300,000$
  • $|S|$ is odd.
  • All characters of $P$ are either '0' or '1'.
  • All characters of $S$ are either '0', '1', or '?'.

예제 입력 1

7
00010111 1??00
00010111 ?
00010111 ?0101???10???00?1???????????????0????????????1????0
01010101 1????
01010101 0????
00001111 1????
00001111 0????

예제 출력 1

2
1
402589311
16
0
8
8

힌트

출처

Contest > Open Cup > 2019/2020 Season > Stage 15: Grand Prix of Tokyo J번

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

출처

대학교 대회

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

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