結果

問題 No.2254 Reverse Only
ユーザー rin204rin204
提出日時 2024-04-29 14:41:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 168,592 KB
最終ジャッジ日時 2024-04-29 14:41:44
合計ジャッジ時間 8,604 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,224 KB
testcase_01 AC 36 ms
52,096 KB
testcase_02 AC 36 ms
51,968 KB
testcase_03 AC 37 ms
52,224 KB
testcase_04 AC 35 ms
51,840 KB
testcase_05 AC 37 ms
52,224 KB
testcase_06 AC 34 ms
51,968 KB
testcase_07 AC 35 ms
52,480 KB
testcase_08 AC 187 ms
115,016 KB
testcase_09 WA -
testcase_10 AC 117 ms
108,952 KB
testcase_11 AC 189 ms
114,812 KB
testcase_12 AC 187 ms
115,400 KB
testcase_13 AC 116 ms
108,748 KB
testcase_14 AC 111 ms
108,864 KB
testcase_15 AC 113 ms
110,456 KB
testcase_16 AC 184 ms
167,352 KB
testcase_17 AC 184 ms
168,524 KB
testcase_18 AC 178 ms
115,660 KB
testcase_19 AC 160 ms
115,016 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 184 ms
147,500 KB
testcase_25 AC 194 ms
143,568 KB
testcase_26 AC 185 ms
143,640 KB
testcase_27 AC 41 ms
60,288 KB
testcase_28 AC 68 ms
79,616 KB
testcase_29 AC 73 ms
99,512 KB
testcase_30 AC 96 ms
98,304 KB
testcase_31 AC 55 ms
78,336 KB
testcase_32 AC 56 ms
81,152 KB
testcase_33 AC 44 ms
68,352 KB
testcase_34 AC 85 ms
106,752 KB
testcase_35 AC 63 ms
91,392 KB
testcase_36 AC 157 ms
107,040 KB
testcase_37 AC 161 ms
107,764 KB
testcase_38 AC 50 ms
73,856 KB
testcase_39 AC 148 ms
103,656 KB
testcase_40 AC 40 ms
60,416 KB
testcase_41 AC 61 ms
87,296 KB
testcase_42 AC 50 ms
73,984 KB
testcase_43 AC 83 ms
104,192 KB
testcase_44 AC 109 ms
107,404 KB
testcase_45 AC 118 ms
103,296 KB
testcase_46 AC 38 ms
59,648 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[::-1] + 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