CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!)
H1
Cyclic Hamming (Easy Version)
Codeforces
3400
原题
← GH2 →
翻译中…

This is the easy version of the problem. The only difference between the two versions is the constraint on $k$. You can make hacks only if all versions of the problem are solved.

翻译中…

In this statement, all strings are $0$-indexed.

翻译中…

For two strings $a$, $b$ of the same length $p$, we define the following definitions:

翻译中…
  • The hamming distance between $a$ and $b$, denoted as $h(a, b)$, is defined as the number of positions $i$ such that $0 \le i \lt p$ and $a_i \ne b_i$.
  • $b$ is a cyclic shift of $a$ if there exists some $0 \leq k \lt p$ such that $b_{(i+k) \bmod p} = a_i$ for all $0 \le i \lt p$. Here $x \bmod y$ denotes the remainder from dividing $x$ by $y$.
翻译中…

You are given two binary strings $s$ and $t$ of length $2^{k+1}$ each. Both strings may contain missing characters (denoted by the character '?'). Your task is to count the number of ways to replace the missing characters in both strings with the characters '0' or '1' such that:

翻译中…
  • Each string $s$ and $t$ contains exactly $2^k$ occurrences of each character '0' and '1'
  • $h(s, c) \ge 2^k$ for all strings $c$ that is a cyclic shift of $t$.
翻译中…

As the result can be very large, you should print the value modulo $998\,244\,353$.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $k$ ($1 \le k \le 7$).

翻译中…

The second line of the input contains string $s$ of size $2^{k+1}$, consisting of the characters '0', '1' and '?'.

翻译中…

The third line of the input contains string $t$ of size $2^{k+1}$, consisting of the characters '0', '1' and '?'.

翻译中…

It is guaranteed that both strings $s$ and $t$ contains no more than $2^k$ character '0' or '1'.

翻译中…

Output

翻译中…

Print a single integer — the answer to the problem modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first example, we can check that the condition $h(s, c) \ge 2^k$ for all cyclic shift $c$ of $t$ is satisfied. In particular:

翻译中…
  • for $c = \mathtt{0101}$, $h(s, c) = h(\mathtt{0110}, \mathtt{0101}) = 2 \ge 2^1$;
  • for $c = \mathtt{1010}$, $h(s, c) = h(\mathtt{0110}, \mathtt{1010}) = 2 \ge 2^1$.
翻译中…

In the second example, there exists a cycle shift $c$ of $t$ such that $h(s, c) \lt 2^k$ (in particular, $c = \mathtt{0011}$, and $h(s, c) = h(\mathtt{0011}, \mathtt{0011}) = 0$).

翻译中…

In the third example, there are $2$ possible ways to recover the missing characters:

翻译中…
  • $s = \mathtt{0101}$, $t = \mathtt{0110}$;
  • $s = \mathtt{0011}$, $t = \mathtt{0101}$.
翻译中…

In the fourth example, there are $3$ possible ways to recover the missing characters:

翻译中…
  • $s = \mathtt{00011110}$, $t = \mathtt{01010101}$;
  • $s = \mathtt{00011011}$, $t = \mathtt{01010101}$;
  • $s = \mathtt{00001111}$, $t = \mathtt{01010101}$.
翻译中…

样例

Input #1
1
0011
0101
Output #1
1
InputCopy OutputCopy
Input #2
1
0011
0110
Output #2
0
InputCopy OutputCopy
Input #3
1
0??1
01??
Output #3
2
InputCopy OutputCopy
Input #4
2
000?????
01010101
Output #4
3
InputCopy OutputCopy
Input #5
2
0???????
1???????
Output #5
68
InputCopy OutputCopy
Input #6
5
0101010101010101010101010101010101010101010101010101010101010101
????????????????????????????????????????????????????????????????
Output #6
935297567
InputCopy OutputCopy
题目信息
题号
1896H1
时间限制
2 s
内存限制
256 MB
标签
暴力
分治
动态规划
FFT
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。