| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 (추가 시간 없음) | 1024 MB | 8 | 3 | 3 | 75.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' :
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.
7 00010111 1??00 00010111 ? 00010111 ?0101???10???00?1???????????????0????????????1????0 01010101 1???? 01010101 0???? 00001111 1???? 00001111 0????
2 1 402589311 16 0 8 8