Universal Cup Judging System

Universal Cup

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

有一个 $n$ 行 $m$ 列的网格。每个单元格中都有一个整数,其中 $a_{i,j}$ 表示位于第 $i$ 行第 $j$ 列单元格中的整数。

令 $(i, j)$ 为位于第 $i$ 行第 $j$ 列的单元格。你现在从 $(1, 1)$ 出发,需要到达 $(n, m)$。当你位于单元格 $(i, j)$ 时,如果 $j < m$,你可以移动到其右侧的单元格 $(i, j + 1)$;如果 $i < n$,你可以移动到其下方的单元格 $(i + 1, j)$。

令 $\mathbb{S}$ 为路径上所有单元格中整数组成的集合,包含 $a_{1,1}$ 和 $a_{n,m}$。一条路径的值定义为 $\mathbb{S}$ 中元素的个数(回想一下,集合不包含重复元素)。请计算所有可能路径的值之和。

输入格式

输入包含多个测试用例。第一行包含一个整数 $T$ ($1 \le T \le 10^3$),表示测试用例的数量。对于每个测试用例:

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 10^5, 1 \le n \times m \le 10^5$),表示网格的行数和列数。

接下来的 $n$ 行中,第 $i$ 行包含 $m$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,m}$ ($1 \le a_{i,j} \le n \times m$),其中 $a_{i,j}$ 表示单元格 $(i, j)$ 中的整数。

保证所有测试用例的 $n \times m$ 之和不超过 $10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示所有可能路径的值之和。由于答案可能很大,请输出其对 $998\,244\,353$ 取模的结果。

样例

样例输入 1

3
2 3
5 2 1
1 5 5
1 1
1
2 3
3 3 3
3 3 3

样例输出 1

7
1
3

说明

对于第一个样例测试用例,共有 3 条可能的路径。

  • 第一条路径是 $(1, 1) \to (1, 2) \to (1, 3) \to (2, 3)$。$\mathbb{S} = \{1, 2, 5\}$。
  • 第二条路径是 $(1, 1) \to (1, 2) \to (2, 2) \to (2, 3)$。$\mathbb{S} = \{2, 5\}$。
  • 第三条路径是 $(1, 1) \to (2, 1) \to (2, 2) \to (2, 3)$。$\mathbb{S} = \{1, 5\}$。

因此答案为 $3 + 2 + 2 = 7$。

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.