結果

問題 No.2254 Reverse Only
ユーザー lam6er
提出日時 2025-04-16 15:56:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,468 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 183,900 KB
最終ジャッジ日時 2025-04-16 15:59:00
合計ジャッジ時間 8,961 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter, defaultdict

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    k = int(input[ptr])
    ptr += 1
    A = list(map(int, input[ptr:ptr+N]))
    ptr += N
    B = list(map(int, input[ptr:ptr+N]))
    ptr += N
    
    if k == 1:
        if A == B:
            print("Yes")
        else:
            print("No")
        return
    
    if (k % 2 == 0) or (k % 2 == 1 and N >= k + 1):
        if Counter(A) == Counter(B):
            print("Yes")
        else:
            print("No")
    else:
        # Check both multisets and parity counts
        countA = Counter(A)
        countB = Counter(B)
        if countA != countB:
            print("No")
            return
        
        a_odd = defaultdict(int)
        a_even = defaultdict(int)
        b_odd = defaultdict(int)
        b_even = defaultdict(int)
        
        for i in range(N):
            pos = i + 1
            a = A[i]
            b = B[i]
            if pos % 2 == 1:
                a_odd[a] += 1
                b_odd[b] += 1
            else:
                a_even[a] += 1
                b_even[b] += 1
        
        valid = True
        for x in countA:
            if a_odd[x] != b_odd[x] or a_even[x] != b_even[x]:
                valid = False
                break
        if valid:
            print("Yes")
        else:
            print("No")

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