No.3486 Draw a Rainbow
タグ : / 解いたユーザー数 38
作問者 : 👑
hamamu
Problem Statement
There are $2$ countries, the yuki country and the coder country, which have different cultures regarding colors. Because of this cultural difference, these $2$ countries are characterized by describing the color of even the same object differently.
Also, because of the cultural difference, the colors that make up a rainbow differ between the yuki country and the coder country.
Specifically, in the yuki country a rainbow consists of the $M$ colors $1, 2, \dots, M$, and in the coder country a rainbow consists of the $L$ colors $M + 1, M + 2, \dots, M + L$.
There are $N$ pens here. The $i$-th pen has color $A_i(1 \leq A_i \leq M)$ in the yuki country and color $B_i(M + 1 \leq B_i \leq M + L)$ in the coder country.
Note that there is no correspondence of colors between the $2$ countries across different pens. (For distinct $i, j$, even if $A_i = A_j$, it is not necessarily the case that $B_i = B_j$.)
There are $2^N - 1$ ways to choose at least $1$ of the $N$ pens. Among them, find the number of ways that satisfy the following condition.
- For both the yuki country and the coder country, the chosen pens include all the colors that make up a rainbow in that country.
Since the answer can be very large, output it modulo $998244353$.
Constraints
- All inputs are integers.
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq M, L \leq 18$
- $1 \leq A_i \leq M$
- $M + 1 \leq B_i \leq M + L$
Input
The input is given from Standard Input in the following format.
$N$ $M$ $L$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_N$ $B_N$
Output
Output the number of ways to choose pens satisfying the condition, modulo $998244353$.
Sample
Sample 1
Input
4 2 2 1 3 1 4 2 3 2 4
Output
7
For example, if you choose the $1$-st pen and the $4$-th pen, color $1$ is included in the $1$-st pen and color $2$ is included in the $4$-th pen, so all the colors that make up a rainbow in the yuki country are included.
In the coder country as well, color $3$ is included in the $1$-st pen and color $4$ is included in the $4$-th pen. Therefore, this choice satisfies the condition.
Letting $S$ be the set of chosen pens, the $S$ that satisfy the condition are the following $7$ ways: $\{1, 4\}, \{2, 3\}, \{1, 2, 3\}, \{1, 2, 4\}, \{1, 3, 4\}, \{2, 3, 4\}, \{1, 2, 3, 4\}$.
Sample 2
Input
2 2 2 1 3 1 3
Output
0
There may be colors that are not included in any pen.
Sample 3
Input
12 3 4 1 5 2 5 2 4 1 6 3 7 3 4 2 6 1 4 2 7 1 7 3 5 3 6
Output
2161
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。