Logo
(追記) (追記ここまで)

33297번 - Periodic Sequence 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB89191230.769%

문제

As you may know, some fractions of integers $\frac{A}{B}$ result in an infinite periodic decimal representation. For example, $\frac{4}{7}$ results in 0ドル.57\overline{142857},ドル which means that the 142857ドル$ part is repeating itself. Note that we could also write 0ドル.5714\overline{285714}$ or 0ドル.571\overline{428571428571}$. As you see, it is not trivial to check if two such sequences are equal.

Therefore, you have to help us. You are given only the periodic part of two sequences and need to check if they are equal. Note that the periodic parts are considered equal if they can be made equal by repetition and cyclic shifting.

입력

The first line contains two integers $n$ and $m$ (1ドル \leq n, m \leq 5 \cdot 10^5$) --- the length of the first and second sequence.

The second line contains $n$ integers $a_i$ (0ドル \leq a_i < 10$) --- the first sequence.

The third line contains $m$ integers $b_i$ (0ドル \leq b_i < 10$) --- the second sequence.

출력

Print YES if the two sequences are equal and NO if they are not.

제한

예제 입력 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

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 5: Der Kontest F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /