QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17887. 패턴

统计

在解锁安卓手机屏幕的方法中,有一种是通过连接 $3 \times 3$ 的 $9$ 个点,将绘制出的图案作为密码。如果给每个点进行编号,并用一个序列来表示图案,那么按顺序连接序列中相邻编号的点所绘制的路径就称为图案。此时,图案的长度就是表示该图案的序列的长度。

图案有以下限制:

  • 图案的长度至少为 $3$。
  • 图案中同一个点最多出现一次。
  • 连接两个点的线段上不能包含尚未出现过的点。

给定一个输入的图案,请判断它是否是一个有效的图案。

输入格式

第一行输入图案的长度 $L$。($3 \le L \le 9$)

第二行输入 $L$ 个整数 $a_1, \cdots, a_L$。这表示图案依次经过编号为 $a_1, \ldots, a_L$ 的点。($1 \le a_i \le 9$)

输出格式

如果图案有效,输出 "YES";否则,输出 "NO"。

样例

输入样例 1

8
9 2 7 6 1 8 3 4

输出样例 1

YES

输入样例 2

4
5 8 7 9

输出样例 2

YES

输入样例 3

4
2 8 7 9

输出样例 3

NO

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.