QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 64 MB Puntuación total: 100

#7213. 相似子序列

Estadísticas

两个序列 $\{a_1, a_2, \dots, a_n\}$ 和 $\{b_1, b_2, \dots, b_n\}$ 是相似的,当且仅当对于所有 $1 \le i, j \le n$,满足 $(a_i - a_j) \cdot (b_i - b_j) > 0$。

Bobo 有两个序列 $A = \{a_1, a_2, \dots, a_n\}$ 和 $B = \{b_1, b_2, \dots, b_m\}$,他想检查 $B$ 是否包含一个与 $A$ 相似的子序列。

输入格式

第一行包含两个整数 $n, m$ ($1 \le n, m \le 500$)。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$)。 第三行包含 $m$ 个整数 $b_1, b_2, \dots, b_m$ ($1 \le b_i \le m$)。

保证 $A$ 是 $\{1, 2, \dots, n\}$ 的一个排列,且不包含任何与 $\{2, 1, 3\}$ 或 $\{2, 3, 1\}$ 相似的子序列。

输出格式

如果 $B$ 包含一个与 $A$ 相似的子序列,输出 “Yes”,否则输出 “No”。

样例

输入格式 1

3 4
1 2 3
1 3 2 4

输出格式 1

Yes

输入格式 2

3 4
1 2 3
4 4 4 4

输出格式 2

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.