結果

問題 No.2254 Reverse Only
ユーザー rin204rin204
提出日時 2024-04-29 14:48:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 943 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 82,524 KB
実行使用メモリ 175,104 KB
最終ジャッジ日時 2024-04-29 14:49:05
合計ジャッジ時間 7,594 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,968 KB
testcase_01 AC 37 ms
51,968 KB
testcase_02 AC 36 ms
52,224 KB
testcase_03 AC 37 ms
52,608 KB
testcase_04 AC 37 ms
51,584 KB
testcase_05 AC 36 ms
51,712 KB
testcase_06 AC 36 ms
52,224 KB
testcase_07 AC 37 ms
52,096 KB
testcase_08 AC 187 ms
114,436 KB
testcase_09 AC 197 ms
173,956 KB
testcase_10 AC 112 ms
108,444 KB
testcase_11 AC 180 ms
114,808 KB
testcase_12 AC 182 ms
115,064 KB
testcase_13 AC 116 ms
108,164 KB
testcase_14 AC 114 ms
108,412 KB
testcase_15 AC 116 ms
109,960 KB
testcase_16 AC 189 ms
173,304 KB
testcase_17 AC 192 ms
175,104 KB
testcase_18 AC 183 ms
115,576 KB
testcase_19 AC 165 ms
115,220 KB
testcase_20 AC 187 ms
174,736 KB
testcase_21 AC 217 ms
174,372 KB
testcase_22 AC 196 ms
142,592 KB
testcase_23 AC 197 ms
146,700 KB
testcase_24 AC 198 ms
146,220 KB
testcase_25 AC 197 ms
142,096 KB
testcase_26 AC 198 ms
141,844 KB
testcase_27 AC 39 ms
60,288 KB
testcase_28 AC 68 ms
79,488 KB
testcase_29 AC 74 ms
99,840 KB
testcase_30 AC 104 ms
98,664 KB
testcase_31 AC 57 ms
78,464 KB
testcase_32 AC 60 ms
81,280 KB
testcase_33 AC 51 ms
68,224 KB
testcase_34 AC 84 ms
106,820 KB
testcase_35 AC 66 ms
91,648 KB
testcase_36 AC 187 ms
106,908 KB
testcase_37 AC 174 ms
107,860 KB
testcase_38 AC 54 ms
74,112 KB
testcase_39 AC 162 ms
103,356 KB
testcase_40 AC 41 ms
60,032 KB
testcase_41 AC 66 ms
87,808 KB
testcase_42 AC 53 ms
74,752 KB
testcase_43 AC 87 ms
104,444 KB
testcase_44 AC 110 ms
107,208 KB
testcase_45 AC 122 ms
103,296 KB
testcase_46 AC 40 ms
59,392 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