結果

問題 No.2254 Reverse Only
ユーザー 👑 rin204rin204
提出日時 2024-04-29 14:42:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 944 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 167,116 KB
最終ジャッジ日時 2024-04-29 14:42:13
合計ジャッジ時間 7,243 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,840 KB
testcase_01 AC 39 ms
51,840 KB
testcase_02 AC 38 ms
51,840 KB
testcase_03 AC 39 ms
51,840 KB
testcase_04 AC 38 ms
51,968 KB
testcase_05 AC 38 ms
51,712 KB
testcase_06 AC 38 ms
51,968 KB
testcase_07 AC 37 ms
51,712 KB
testcase_08 AC 192 ms
114,304 KB
testcase_09 WA -
testcase_10 AC 115 ms
108,636 KB
testcase_11 AC 183 ms
114,428 KB
testcase_12 AC 184 ms
115,072 KB
testcase_13 AC 120 ms
108,040 KB
testcase_14 AC 115 ms
108,668 KB
testcase_15 AC 125 ms
110,592 KB
testcase_16 AC 188 ms
165,624 KB
testcase_17 AC 188 ms
166,652 KB
testcase_18 AC 179 ms
115,400 KB
testcase_19 AC 162 ms
115,028 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 201 ms
145,916 KB
testcase_25 AC 191 ms
141,724 KB
testcase_26 AC 205 ms
142,104 KB
testcase_27 AC 40 ms
60,032 KB
testcase_28 AC 63 ms
79,616 KB
testcase_29 AC 78 ms
99,456 KB
testcase_30 AC 99 ms
98,176 KB
testcase_31 AC 53 ms
78,464 KB
testcase_32 AC 63 ms
80,768 KB
testcase_33 AC 46 ms
68,096 KB
testcase_34 AC 89 ms
106,496 KB
testcase_35 AC 67 ms
91,264 KB
testcase_36 AC 164 ms
106,912 KB
testcase_37 AC 164 ms
108,012 KB
testcase_38 AC 49 ms
73,728 KB
testcase_39 AC 172 ms
103,608 KB
testcase_40 AC 38 ms
60,160 KB
testcase_41 AC 63 ms
87,936 KB
testcase_42 AC 54 ms
74,240 KB
testcase_43 AC 95 ms
104,448 KB
testcase_44 AC 110 ms
107,004 KB
testcase_45 AC 122 ms
103,424 KB
testcase_46 AC 39 ms
59,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Z_algorithm(S):
    le = len(S)
    Z = [0] * le
    Z[0] = le
    i = 1
    j = 0
    while i < le:
        while i + j < le and S[j] == S[i + j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
            continue

        k = 1
        while i + k < le and k + Z[k] < j:
            Z[i + k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z


n, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if A == B:
    print("Yes")
elif n < k:
    print("No")
elif n == k:
    if A == B[::-1]:
        print("Yes")
    else:
        print("No")
elif n == k + 1:
    C = B + A + A
    D = B + A[::-1] + A[::-1]
    Z1 = Z_algorithm(C)
    Z2 = Z_algorithm(D)
    ma = max(*Z1[:n:], *Z2[n:])
    if ma >= n:
        print("Yes")
    else:
        print("No")
else:
    if sorted(A) == sorted(B):
        print("Yes")
    else:
        print("No")
0