結果

問題 No.2254 Reverse Only
ユーザー titiatitia
提出日時 2023-04-09 02:25:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,548 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 57,008 KB
最終ジャッジ日時 2024-04-14 21:06:04
合計ジャッジ時間 18,900 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 30 ms
11,008 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 30 ms
11,008 KB
testcase_08 AC 278 ms
38,512 KB
testcase_09 WA -
testcase_10 AC 167 ms
38,540 KB
testcase_11 AC 278 ms
38,316 KB
testcase_12 AC 268 ms
38,384 KB
testcase_13 AC 288 ms
38,404 KB
testcase_14 AC 280 ms
38,524 KB
testcase_15 AC 288 ms
38,520 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 264 ms
38,380 KB
testcase_19 AC 231 ms
38,532 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 36 ms
11,776 KB
testcase_28 AC 76 ms
17,360 KB
testcase_29 AC 138 ms
23,468 KB
testcase_30 AC 123 ms
22,028 KB
testcase_31 AC 79 ms
17,732 KB
testcase_32 AC 85 ms
18,440 KB
testcase_33 AC 55 ms
14,444 KB
testcase_34 AC 172 ms
27,156 KB
testcase_35 AC 117 ms
21,356 KB
testcase_36 AC 238 ms
35,560 KB
testcase_37 AC 249 ms
35,204 KB
testcase_38 AC 68 ms
16,328 KB
testcase_39 AC 223 ms
32,388 KB
testcase_40 AC 36 ms
11,776 KB
testcase_41 AC 107 ms
20,824 KB
testcase_42 AC 72 ms
16,744 KB
testcase_43 AC 181 ms
29,500 KB
testcase_44 AC 266 ms
36,736 KB
testcase_45 AC 167 ms
26,852 KB
testcase_46 AC 34 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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")
    exit()

if K==N:
    if A==B or A==B[::-1]:
        print("Yes")
    else:
        print("No")
    exit()

elif K>N:
    if A==B:
        print("Yes")
    else:
        print("No")
    exit()

elif K<N-1:
    print("Yes")
    exit()

# Rolling Hash

LEN=N

p=200000 # 文字の種類
mod=67280421310721 # Hashがぶつからない, pと互いに素な数を適当に指定
INV=pow(p,mod-2,mod)
kake=pow(p,LEN-1,mod)

score=0
for i in range(N):
    score=(score*p%mod+B[i])%mod

TABLE=[0] # Rolling Hashのテーブル. 最初は0

for i in range(N):
    TABLE.append((p*TABLE[-1]%mod+A[i])%mod) # テーブルを埋める

def hash_ij(i,j): # [i,j)のハッシュ値を求める
    return (TABLE[j]-TABLE[i]*pow(p,j-i,mod))%mod

LIST=[TABLE[-1]]

now=TABLE[-1]

for i in range(N-1,-1,-1):
    a=A[i]
    now-=a

    now=now*INV%mod

    now=(now+a*kake)%mod

    LIST.append(now)

print(LIST)

TABLE=[0] # Rolling Hashのテーブル. 最初は0
A=A[::-1]

for i in range(N):
    TABLE.append((p*TABLE[-1]%mod+A[i])%mod) # テーブルを埋める

def hash_ij(i,j): # [i,j)のハッシュ値を求める
    return (TABLE[j]-TABLE[i]*pow(p,j-i,mod))%mod

LIST.append(TABLE[-1])

now=TABLE[-1]
for i in range(N-1,-1,-1):
    a=A[i]
    now-=a
    now=now*INV%mod
    now=(now+a*kake)%mod
    LIST.append(now)

if score in LIST:
    print("Yes")
else:
    print("No")
0