問題一覧 > 通常問題

No.3486 Draw a Rainbow

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 4.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 38
作問者 : 👑 AngrySadEight / テスター : 👑 binap 👑 hamamu
お気に入りにしたユーザー ProblemId : 12964 / 自分の提出
問題文最終更新日: 2026-03-20 01:49:51
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 495 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。