QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#4192. 索引案例

统计

流行病学家 W. Andy 想要找到一场正在进行的危机的索引病例。为此,他用元胞自动机对疫情爆发的城市及其 $n$ 名居民进行了建模。城市由编号为 $1$ 到 $n$ 的 $n$ 个单元格表示,每个单元格有两个相邻的单元格,一个在左侧,一个在右侧。单元格 $i$ 的左邻居是单元格 $i-1$,右邻居是单元格 $i+1$。此外,单元格 $1$ 的左邻居是单元格 $n$,单元格 $n$ 的右邻居是单元格 $1$。因此,城市和相应的自动机形成了一个简单的环。

每个单元格包含一个 $1$ 到 $m$ 之间的整数,代表该人被感染的可能性。由于病毒只能通过个人接触传播,第 $d$ 天第 $i$ 个单元格的值仅取决于前一天其邻居和自身的值。如果我们用 $s_d[i]$ 表示该值,则疫情爆发可以通过函数 $f$ 使用以下公式进行模拟:

$$s_d[i] = f(s_{d-1}[i-1], s_{d-1}[i], s_{d-1}[i+1])$$

注意,由于城市是循环的,因此 $i+1$ 和 $i-1$ 均按模 $n$ 计算。

Andy 想要找到索引病例,所以他首先必须找到 $s_0$,即第零天城市的状态。然而,这带来了一个问题,因为不知道危机是从哪一天开始的。目前,Andy 认为他已经完成了任务并找到了状态 $s_0$,但你并不信服。因此,你想要检查是否存在一个先于 Andy 提出的初始状态的状态,即是否存在任何状态 $s_{-1}$,通过应用 $f$ 可以转化为 $s_0$。

输入格式

输入包含: 一行,包含两个整数 $n$ 和 $m$ ($3 \le n \le 200, 2 \le m \le 10$),分别表示单元格数量和状态数量。 $m^3$ 行,描述了模拟自动机的函数 $f$ 的值 $f(x, y, z)$ ($1 \le f(x, y, z) \le m$,对于每个 $1 \le x, y, z \le m$)。这些值按参数的字典序给出:第一个值是 $f(1, 1, 1)$,下一个是 $f(1, 1, 2)$,依此类推直到 $f(1, 1, m)$,接着是 $f(1, 2, 1)$ 等等。最后一个值是 $f(m, m, m)$。 * 一行,包含 $n$ 个整数 $s_0[1], \dots, s_0[n]$ ($1 \le s_0[i] \le m$,对于每个 $i$),即 Andy 提出的初始状态。

输出格式

如果存在至少一个可能的前驱状态,输出 yes,否则输出 no

样例

样例输入 1

4 2
1
2
1
2
2
1
2
1
1 2 1 2

样例输出 1

yes

样例输入 2

6 2
1
2
1
2
2
1
2
1
1 2 1 2 1 2

样例输出 2

no

样例输入 3

10 2
1
2
1
1
2
2
2
2
1 2 2 2 1 2 1 2 1 2

样例输出 3

yes

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.