QOJ.ac

QOJ

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

#10041. 周期序列

统计

如你所知,某些整数分数 $\frac{A}{B}$ 会产生无限循环小数表示。例如,$\frac{4}{7}$ 的结果为 $0.\overline{571428}$,这意味着 $142857$ 部分在不断重复。注意,我们也可以将其写为 $0.5714285714$ 或 $0.571428571428571$。如你所见,判断两个这样的序列是否相等并非易事。

因此,你需要帮助我们。给定两个序列的循环部分,你需要判断它们是否相等。注意,如果两个循环部分可以通过重复和循环移位变得相等,则认为它们是相等的。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 5 \cdot 10^5$),分别表示第一个序列和第二个序列的长度。

第二行包含 $n$ 个整数 $a_i$ ($0 \le a_i < 10$),表示第一个序列。

第三行包含 $m$ 个整数 $b_i$ ($0 \le b_i < 10$),表示第二个序列。

输出格式

如果两个序列相等,输出 YES,否则输出 NO。

样例

样例输入 1

6 3
1 5 6 1 5 6
6 1 5

样例输出 1

YES

样例输入 2

7 3
1 5 6 1 5 6 7
5 6 7

样例输出 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.