結果

問題 No.2254 Reverse Only
ユーザー sotanishysotanishy
提出日時 2023-03-24 21:52:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 134,700 KB
最終ジャッジ日時 2023-10-18 21:00:16
合計ジャッジ時間 8,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,452 KB
testcase_01 AC 37 ms
53,452 KB
testcase_02 AC 36 ms
53,452 KB
testcase_03 AC 37 ms
53,452 KB
testcase_04 AC 37 ms
53,452 KB
testcase_05 AC 38 ms
53,452 KB
testcase_06 AC 37 ms
53,452 KB
testcase_07 AC 37 ms
53,452 KB
testcase_08 AC 195 ms
113,292 KB
testcase_09 AC 210 ms
134,364 KB
testcase_10 AC 124 ms
110,252 KB
testcase_11 AC 194 ms
113,312 KB
testcase_12 AC 190 ms
113,680 KB
testcase_13 AC 199 ms
113,016 KB
testcase_14 AC 194 ms
113,880 KB
testcase_15 AC 199 ms
114,876 KB
testcase_16 AC 216 ms
132,696 KB
testcase_17 AC 215 ms
134,068 KB
testcase_18 AC 188 ms
113,880 KB
testcase_19 AC 170 ms
113,464 KB
testcase_20 AC 190 ms
134,504 KB
testcase_21 AC 190 ms
134,700 KB
testcase_22 AC 145 ms
127,804 KB
testcase_23 AC 151 ms
130,588 KB
testcase_24 AC 157 ms
131,692 KB
testcase_25 AC 160 ms
131,644 KB
testcase_26 AC 162 ms
131,648 KB
testcase_27 AC 43 ms
61,512 KB
testcase_28 AC 71 ms
79,648 KB
testcase_29 AC 113 ms
103,412 KB
testcase_30 AC 101 ms
97,248 KB
testcase_31 AC 73 ms
81,360 KB
testcase_32 AC 78 ms
85,488 KB
testcase_33 AC 56 ms
70,980 KB
testcase_34 AC 133 ms
104,888 KB
testcase_35 AC 96 ms
95,636 KB
testcase_36 AC 170 ms
106,680 KB
testcase_37 AC 179 ms
107,576 KB
testcase_38 AC 64 ms
75,836 KB
testcase_39 AC 159 ms
103,308 KB
testcase_40 AC 43 ms
61,512 KB
testcase_41 AC 90 ms
91,364 KB
testcase_42 AC 66 ms
78,068 KB
testcase_43 AC 139 ms
102,616 KB
testcase_44 AC 185 ms
111,812 KB
testcase_45 AC 129 ms
101,976 KB
testcase_46 AC 42 ms
61,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def z_array(s):
    n = len(s)
    z = [0] * n
    z[0] = n
    l = r = 0
    for i in range(1, n):
        k = i - l
        if i <= r and z[k] < r - i + 1:
            z[i] = z[k]
        else:
            l = i
            if i > r:
                r = i
            while r < n and s[r - l] == s[r]:
                r += 1
            r -= 1
            z[i] = r - l + 1
    return z


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

if sorted(A) != sorted(B):
    print("No")
elif A == B:
    print("Yes")
elif k > N:
    print("No")
elif k <= N-2:
    # rotation + swap
    print("Yes")
elif k == N-1:
    # rotation
    z = z_array(B + [0] + A + A)
    for i in range(N):
        if z[N+1+i] >= N:
            print("Yes")
            exit()
    print("No")
else:
    # k == N
    print("Yes" if A[::-1] == B else "No")
0