AT_arc218_a.Many Sets

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given NN sequences of positive integers, each of length MM. The ii-th sequence is Ai=(Ai,1,Ai,2,…,Ai,M)A_i=(A_{i,1},A_{i,2},\dots,A_{i,M}).

There are MNM^N ways to choose one element from each of these NN sequences. Find the sum, modulo 998244353998244353, of "the number of distinct integers among the chosen elements" over all such ways.

给你 NN 个正整数序列,每个序列的长度均为 MM。第 ii 个序列为 Ai=(Ai,1,Ai,2,…,Ai,M)A_i=(A_{i,1},A_{i,2},\dots,A_{i,M})。

从这 NN 个序列中各选一个元素,共有 MNM^N 种选择方式。对所有这些选择方式,求“所选元素中不同整数的个数”的总和,并将结果对 998244353998244353 取模。

输入格式

The input is given from Standard Input in the following format:

NN MM
A1,1A_{1,1} A1,2A_{1,2} …\dots A1,MA_{1,M}
A2,1A_{2,1} A2,2A_{2,2} …\dots A2,MA_{2,M}
⋮\vdots
AN,1A_{N,1} AN,2A_{N,2} …\dots AN,MA_{N,M}

输入从标准输入中按以下格式给出:

NN MM
A1,1A_{1,1} A1,2A_{1,2} …\dots A1,MA_{1,M}
A2,1A_{2,1} A2,2A_{2,2} …\dots A2,MA_{2,M}
⋮\vdots
AN,1A_{N,1} AN,2A_{N,2} …\dots AN,MA_{N,M}

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    2 2
    1 3
    2 3

    输出#1

    7
  • 输入#2

    2 2
    1 1
    1 2

    输出#2

    6
  • 输入#3

    3 5
    3 1 3 4 2
    5 2 1 2 3
    4 6 2 5 6

    输出#3

    327

说明/提示

Sample 1 Explanation:
For example, if A1,1A_{1,1} and A2,1A_{2,1} are chosen, there are two distinct integers among the chosen elements: 11 and 22.

The number of distinct integers is 11 only when A1,2A_{1,2} and A2,2A_{2,2} are chosen, and it is 22 in the other three cases, so the answer is 77.

Constraints

  • 1≤N,M≤5001 \le N,M \le 500
  • 1≤Ai,j≤NM1 \le A_{i,j} \le NM
  • All input values are integers.

样例 1 解释:
例如,若选择 A1,1A_{1,1} 和 A2,1A_{2,1},则所选元素中包含两个不同的整数:11 和 22。

仅当选择 A1,2A_{1,2} 和 A2,2A_{2,2} 时,所选元素中不同整数的个数为 11;其余三种情况中,不同整数的个数均为 22,因此答案为 77。

约束条件

  • 1≤N,M≤5001 \le N,M \le 500
  • 1≤Ai,j≤NM1 \le A_{i,j} \le NM
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页