結果

問題 No.2254 Reverse Only
ユーザー gew1fw
提出日時 2025-06-12 14:47:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 182,288 KB
最終ジャッジ日時 2025-06-12 14:49:27
合計ジャッジ時間 10,493 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict, Counter

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 Counter(A) != Counter(B):
        print("No")
        return
    
    if k > n:
        if A == B:
            print("Yes")
        else:
            print("No")
        return
    
    if k == 1:
        print("Yes")
        return
    
    if k % 2 == 0:
        print("Yes")
        return
    
    # Check parity counts for odd k
    a_odd = defaultdict(int)
    a_even = defaultdict(int)
    for idx, num in enumerate(A):
        pos = idx + 1
        if pos % 2 == 1:
            a_odd[num] += 1
        else:
            a_even[num] += 1
    
    b_odd = defaultdict(int)
    b_even = defaultdict(int)
    for idx, num in enumerate(B):
        pos = idx + 1
        if pos % 2 == 1:
            b_odd[num] += 1
        else:
            b_even[num] += 1
    
    all_elements = set(A) | set(B)
    for num in all_elements:
        if a_odd.get(num, 0) != b_odd.get(num, 0) or a_even.get(num, 0) != b_even.get(num, 0):
            print("No")
            return
    print("Yes")

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