結果
問題 |
No.2254 Reverse Only
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:47:15 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,494 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 82,700 KB |
実行使用メモリ | 174,032 KB |
最終ジャッジ日時 | 2025-06-12 14:49:53 |
合計ジャッジ時間 | 8,911 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 15 |
ソースコード
from collections import defaultdict, Counter 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 # Check if the multisets of A and B are the same if Counter(A) != Counter(B): print("No") return # If k is even or 1, output Yes if k % 2 == 0 or k == 1: print("Yes") return # For odd k > 1, check parity of positions for each element def get_parity_counts(arr): counts = defaultdict(lambda: [0, 0]) # [odd_count, even_count] for idx, num in enumerate(arr): pos = idx + 1 # 1-based position if pos % 2 == 1: counts[num][0] += 1 else: counts[num][1] += 1 return counts a_parity = get_parity_counts(A) b_parity = get_parity_counts(B) # Check if all elements have the same parity counts in A and B # First, collect all unique elements from both (though Counter is same) all_elements = set(a_parity.keys()).union(set(b_parity.keys())) for elem in all_elements: a_odd, a_even = a_parity[elem] b_odd, b_even = b_parity.get(elem, [0, 0]) if a_odd != b_odd or a_even != b_even: print("No") return print("Yes") if __name__ == "__main__": main()