結果

問題 No.2254 Reverse Only
ユーザー gew1fw
提出日時 2025-06-12 18:39:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 82,148 KB
実行使用メモリ 128,164 KB
最終ジャッジ日時 2025-06-12 18:40:17
合計ジャッジ時間 7,550 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    n, k = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    
    if sorted(A) != sorted(B):
        print("No")
        return
    
    if k == 1:
        print("Yes")
        return
    
    if k > n:
        if A == B:
            print("Yes")
        else:
            print("No")
        return
    
    if k % 2 == 0:
        print("Yes")
        return
    
    # k is odd and <= n
    countA_even = defaultdict(int)
    countB_even = defaultdict(int)
    
    for i in range(n):
        x = A[i]
        if (i + 1) % 2 == 0:
            countA_even[x] += 1
    
    for i in range(n):
        x = B[i]
        if (i + 1) % 2 == 0:
            countB_even[x] += 1
    
    for x in set(A):
        if countA_even.get(x, 0) != countB_even.get(x, 0):
            print("No")
            return
    
    print("Yes")

if __name__ == "__main__":
    main()
0