結果
問題 |
No.2254 Reverse Only
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:50:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,541 bytes |
コンパイル時間 | 520 ms |
コンパイル使用メモリ | 81,636 KB |
実行使用メモリ | 195,952 KB |
最終ジャッジ日時 | 2025-04-15 22:52:46 |
合計ジャッジ時間 | 9,702 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 WA * 16 |
ソースコード
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 # Handle k == 1 case if k == 1: if A == B: print("Yes") else: print("No") return # If k is even, output Yes if k % 2 == 0: print("Yes") return # For odd k > 1, check parity of positions for each element cntA_odd = defaultdict(int) cntA_even = defaultdict(int) for i in range(n): pos = i + 1 if pos % 2 == 1: cntA_odd[A[i]] += 1 else: cntA_even[A[i]] += 1 cntB_odd = defaultdict(int) cntB_even = defaultdict(int) for i in range(n): pos = i + 1 if pos % 2 == 1: cntB_odd[B[i]] += 1 else: cntB_even[B[i]] += 1 # Check all elements' parity counts all_elements = set(cntA_odd.keys()) | set(cntA_even.keys()) | set(cntB_odd.keys()) | set(cntB_even.keys()) for x in all_elements: if cntA_odd.get(x, 0) != cntB_odd.get(x, 0) or cntA_even.get(x, 0) != cntB_even.get(x, 0): print("No") return print("Yes") if __name__ == "__main__": main()