結果

問題 No.2254 Reverse Only
ユーザー tassei903tassei903
提出日時 2023-03-24 23:48:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 81,684 KB
実行使用メモリ 139,628 KB
最終ジャッジ日時 2023-10-18 21:41:57
合計ジャッジ時間 7,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,324 KB
testcase_01 AC 40 ms
53,324 KB
testcase_02 AC 40 ms
53,324 KB
testcase_03 AC 38 ms
53,324 KB
testcase_04 AC 39 ms
53,324 KB
testcase_05 AC 39 ms
53,324 KB
testcase_06 AC 40 ms
53,324 KB
testcase_07 AC 40 ms
53,324 KB
testcase_08 AC 204 ms
114,240 KB
testcase_09 AC 147 ms
139,124 KB
testcase_10 AC 125 ms
108,244 KB
testcase_11 AC 199 ms
114,288 KB
testcase_12 AC 198 ms
114,660 KB
testcase_13 AC 127 ms
108,000 KB
testcase_14 AC 122 ms
108,208 KB
testcase_15 AC 128 ms
109,792 KB
testcase_16 AC 146 ms
138,368 KB
testcase_17 AC 147 ms
139,388 KB
testcase_18 AC 198 ms
114,860 KB
testcase_19 AC 180 ms
114,608 KB
testcase_20 AC 146 ms
139,628 KB
testcase_21 AC 146 ms
139,612 KB
testcase_22 AC 142 ms
131,444 KB
testcase_23 AC 159 ms
138,948 KB
testcase_24 AC 153 ms
138,696 KB
testcase_25 AC 153 ms
139,168 KB
testcase_26 AC 154 ms
139,176 KB
testcase_27 AC 44 ms
61,284 KB
testcase_28 AC 72 ms
79,960 KB
testcase_29 AC 84 ms
99,168 KB
testcase_30 AC 108 ms
98,048 KB
testcase_31 AC 59 ms
78,584 KB
testcase_32 AC 64 ms
80,592 KB
testcase_33 AC 50 ms
68,628 KB
testcase_34 AC 93 ms
105,140 KB
testcase_35 AC 71 ms
92,440 KB
testcase_36 AC 176 ms
106,396 KB
testcase_37 AC 181 ms
107,272 KB
testcase_38 AC 56 ms
75,212 KB
testcase_39 AC 166 ms
103,128 KB
testcase_40 AC 44 ms
61,284 KB
testcase_41 AC 69 ms
87,584 KB
testcase_42 AC 55 ms
75,372 KB
testcase_43 AC 95 ms
103,976 KB
testcase_44 AC 118 ms
106,672 KB
testcase_45 AC 134 ms
103,000 KB
testcase_46 AC 44 ms
61,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
def Z_algorithm(s):
    n = len(s)
    Z = [0] * n  # z[i] = sum(s[0::n - i], s[i::n])
    Z[0] = n
    i, j = 1, 0
    while i < n:
        # 共通部分を見つけるパート
        while i + j < n and s[j] == s[i + j]:
            j += 1
        Z[i] = j

        if j == 0:
            i += 1
            continue
        # 計算の再利用パート
        # k + Z[k] < j なら再利用できる
        k = 1
        while k < j and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        # k個先まで見たのでk個先にバトンを渡す
        i += k
        j -= k
    return Z

n,k = na()
a = na()
b = na()

if k <= n-2:
    if sorted(a) == sorted(b):
        Yes()
    else:
        No()
elif k == n:
    if a == b or b == a[::-1]:
        Yes()
    else:
        No()
elif k > n:
    if a == b:
        Yes()
    else:
        No()

else:
    S = a + a + b + b
    z = Z_algorithm(S)
    for i in range(n*2, n*4):
        if z[i] >= n:
            Yes()
            exit()
    No()
0