QOJ.ac

QOJ

Límite de tiempo: 5 s Límite de memoria: 512 MB Puntuación total: 100

#1929. U群のナンパ王

Estadísticas

$\bullet$ 小天使 忆艾 $\bullet$:わあ、一人で UOJ グループで何を探しているの?

「1. 多項式を探す」

「2. 小天使を探す」

$n\times m$ 個のマスがあり、各マスを $k$ 種類の色のいずれかで塗る。集合 $S, T$ に対して、以下の条件を満たす塗り方の総数を求めよ。

  • 各行のパターンを取り出したとき、それと同一のパターンを持つ行の総数(自身を含む)を $r$ とすると、$r\in S$ である。
  • 各列のパターンを取り出したとき、それと同一のパターンを持つ列の総数(自身を含む)を $c$ とすると、$c\in T$ である。

答えは $P = 998244353$ で割った余りを求めよ。

この問題のコードを健全なものにするため、$1\in S \cap T$ であることが保証されている。

入力

1 行目に 5 つの正整数 $n, m, k, a, b$ が与えられる。

続く 1 行に、$a$ 個の正整数が昇順で与えられる。これらは集合 $S$ の要素であり、重複はない。

続く 1 行に、$b$ 個の正整数が昇順で与えられる。これらは集合 $T$ の要素であり、重複はない。

出力

条件を満たす塗り方の総数を $P$ で割った余りを 1 行で出力せよ。

入出力例

入力 1

2 2 2 1 1
1
1

出力 1

10

解説 1

これは、どの 2 行も色が異なり、どの 2 列も色が異なることを意味する。

$2^4 = 16$ 通りの塗り方のうち、以下の $6$ 通りは条件を満たさない。

11 00 01 10 00 11
00 11 01 10 00 11

入力 2

49 50 666 5 4
1 2 6 9 19
1 2 3 5

出力 2

132764272

入力 3

10492 11451 1122334 5 5
1 2 600 9700 10492
1 2 301 3131 4921

出力 3

208881352

小課題

データセットの $10\%$ について、$n, m\le 50$ を満たす。

データセットの $40\%$ について、$n, m\le 3000$ を満たす。

さらに別の $10\%$ のデータセットについて、$S = T = \{1\}$ を満たす。

データセットの $100\%$ について、$1\le n, m\le 10^5, 1\le k\le P - 1, 1\le a, b\le5, 1\in S \cap T, S \subseteq [1, n], T \subseteq [1, m]$ を満たす。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.