QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#174. 校验码的质量

统计

你居住的小城市计划引入一套新的社会保障号码(SSN)系统。每位公民将由一个五位数的 SSN 标识。其前四位数字表示基础 ID 号码(0000–9999),最后一位数字是用于检测错误的校验码。

为了计算校验码,该市决定使用一张运算表。运算表是一个 $10 \times 10$ 的十进制数字表格,其对角线元素均为 0。以下是两张运算表示例。

图 B.1. 两种常见的人类错误

使用运算表,四位基础 ID 号码 $abcd$ 的校验码 $e$ 通过以下公式计算。其中,$i \otimes j$ 表示表中第 $i$ 行第 $j$ 列的元素。

$$e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$$

例如,使用运算表 1,基础 ID 号码 $abcd = 2016$ 的校验码 $e$ 计算如下:

$$e = (((0 \otimes 2) \otimes 0) \otimes 1) \otimes 6$$ $$= (( 1 \otimes 0) \otimes 1) \otimes 6$$ $$= ( 7 \otimes 1) \otimes 6$$ $$= 9 \otimes 6$$ $$= 6$$

因此,SSN 为 20166。

注意,校验码取决于所使用的运算表。对于相同的基本 ID 号码 2016,使用运算表 2 时,$e = 3$,整个 SSN 将为 20163。

添加校验码的目的是为了检测在书写/输入 SSN 时产生的人类错误。以下校验函数可以检测某些人类错误。对于五位数 $abcde$,校验函数定义如下:

$$\text{check}(abcde) = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e$$

该函数对于正确的 SSN 返回 0。这是因为运算表中的每个对角线元素均为 0,且对于正确的 SSN,我们有 $e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$:

$$\text{check}(abcde) = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e = e \otimes e = 0$$

另一方面,校验函数返回非零值表示给定的号码不可能是正确的 SSN。注意,根据所使用的运算表,校验函数可能对错误的 SSN 也返回 0。检测到的错误种类取决于所使用的运算表;表格决定了错误检测的质量。

市政当局希望检测数字序列上的两种常见人类错误:更改单个数字和转置两个相邻数字,如图 B.1 所示。

如果一个运算表能够检测出由 0000–9999 的四位基础 ID 号码生成的所有 SSN 上的上述两种常见错误,则称该运算表是“好的”。注意,校验码的错误以及四个基础 ID 数字的错误都应该被检测出来。例如,运算表 1 是好的。运算表 2 不好,因为对于 20613(这是通过转置正确 SSN 20163 的第 3 位和第 4 位得到的数字),$\text{check}(20613)$ 为 0。实际上,在 10000 个基础 ID 号码中,运算表 2 无法检测出多达 3439 个基础 ID 号码中的一种或多种常见错误。

给定一张运算表,通过计算该表无法检测出一种或多种常见错误的基础 ID 号码数量,来判断它有多好。

输入格式

输入包含单个测试用例,格式如下:

$x_{00} \ x_{01} \ \dots \ x_{09}$ $\vdots$ $x_{90} \ x_{91} \ \dots \ x_{99}$

输入描述了一个运算表,其中 $x_{ij}$ 是第 $i$ 行第 $j$ 列的十进制数字。每一行对应表中的一行,元素之间由单个空格分隔。对角线元素 $x_{ii} \ (i = 0, \dots, 9)$ 始终为 0。

输出格式

输出该表无法检测出一种或多种常见人类错误的基础 ID 号码数量。

样例

样例输入 1

0 3 1 7 5 9 8 6 4 2
7 0 9 2 1 5 4 8 6 3
4 2 0 6 8 7 1 3 5 9
1 7 5 0 9 8 3 4 2 6
6 1 2 3 0 4 5 9 7 8
3 6 7 4 2 0 9 5 8 1
5 8 6 9 7 2 0 1 3 4
8 9 4 5 3 6 2 0 1 7
9 4 3 8 6 1 7 2 0 5
2 5 8 1 4 3 6 7 9 0

样例输出 1

0

样例输入 2

0 1 2 3 4 5 6 7 8 9
9 0 1 2 3 4 5 6 7 8
8 9 0 1 2 3 4 5 6 7
7 8 9 0 1 2 3 4 5 6
6 7 8 9 0 1 2 3 4 5
5 6 7 8 9 0 1 2 3 4
4 5 6 7 8 9 0 1 2 3
3 4 5 6 7 8 9 0 1 2
2 3 4 5 6 7 8 9 0 1
1 2 3 4 5 6 7 8 9 0

样例输出 2

3439

样例输入 3

0 9 8 7 6 5 4 3 2 1
1 0 9 8 7 6 5 4 3 2
2 1 0 9 8 7 6 5 4 3
3 2 1 0 9 8 7 6 5 4
4 3 2 1 0 9 8 7 6 5
5 4 3 2 1 0 9 8 7 6
6 5 4 3 2 1 0 9 8 7
7 6 5 4 3 2 1 0 9 8
8 7 6 5 4 3 2 1 0 9
9 8 7 6 5 4 3 2 1 0

样例输出 3

9995

样例输入 4

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

样例输出 4

10000

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.