luogu#P9752. [CSP-S 2023] 密码锁

[CSP-S 2023] 密码锁

Problem Description

Xiao Y has a combination lock with five dials. As shown in the figure, each dial contains digits from 00 to 99. Each dial is cyclic from 00 to 99, meaning that after turning 99 by one position it can become 00 or 88.

Because the campus is relatively safe, Xiao Y locks his bike in the following way: starting from the correct password, he randomly turns the lock exactly once. Each time, he turns either one dial by some amount, or two adjacent dials at the same time by the same amount.

When Xiao Y chooses to turn two adjacent dials at the same time, the two dials are turned by the same amount. For example, he can change the lock from 0  0  1  1  5\tt{0\;0\;1\;1\;5} to 1  1  1  1  5\tt{1\;1\;1\;1\;5}, but not to 1  2  1  1  5\tt{1\;2\;1\;1\;5}.

Over time, Xiao Y also worries about the security of locking the bike this way, so he wrote down nn states of the lock after locking. Note that none of these nn states is the correct password.

To test how secure this locking method is, how many possible correct passwords are there, such that each correct password can generate all of the given nn lock states after locking, following Xiao Y’s locking method.

Input Format

The first line contains a positive integer nn, indicating the number of lock states after locking.

The next nn lines each contain five integers, describing one state of the combination lock.

Output Format

Output one line containing one integer, indicating how many possible correct passwords can correspond to these nn states under the given locking method.

1
0 0 1 1 5
81

Hint

[Sample 1 Explanation].

There are 8181 possible solutions in total.

Among them, there are 4545 solutions that turn only one dial, and 3636 solutions that turn two dials.

[Sample 2].

See lock/lock2.in and lock/lock2.ans in the contestant directory.

[Constraints].

For all testdata: 1n81 \leq n \leq 8.

Test Point nn\leq Special Property
131\sim 3 11 None
454\sim 5 22
686\sim 8 88 A
9109\sim 10 None

Special Property A: It is guaranteed that all correct passwords can obtain the given nn states by turning only one dial.

Translated by ChatGPT 5