結果
問題 |
No.2254 Reverse Only
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:33:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,425 bytes |
コンパイル時間 | 405 ms |
コンパイル使用メモリ | 82,884 KB |
実行使用メモリ | 160,448 KB |
最終ジャッジ日時 | 2025-06-12 13:40:00 |
合計ジャッジ時間 | 9,820 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 WA * 6 |
ソースコード
from collections import defaultdict def main(): import sys input = sys.stdin.read().split() ptr = 0 N, k = int(input[ptr]), int(input[ptr+1]) ptr += 2 A = list(map(int, input[ptr:ptr+N])) ptr += N B = list(map(int, input[ptr:ptr+N])) ptr += N # Check if A and B are permutations if sorted(A) != sorted(B): print("No") return if k == 1 or k == 2: print("Yes") return if k > N: if A == B: print("Yes") else: print("No") return if k % 2 == 1: # Check parity for each element parity_A = defaultdict(list) for idx, x in enumerate(A): parity = (idx + 1) % 2 # 1-based index parity_A[x].append(parity) parity_B = defaultdict(list) for idx, x in enumerate(B): parity = (idx + 1) % 2 parity_B[x].append(parity) # Verify each element's parity counts match for x in parity_A: if sorted(parity_A[x]) != sorted(parity_B.get(x, [])): print("No") return # Also check for elements in B not in A (though sorted check already passed) for x in parity_B: if x not in parity_A: print("No") return print("Yes") else: print("Yes") if __name__ == "__main__": main()