結果
| 問題 |
No.2254 Reverse Only
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 22:54:55 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,468 bytes |
| コンパイル時間 | 388 ms |
| コンパイル使用メモリ | 81,924 KB |
| 実行使用メモリ | 184,552 KB |
| 最終ジャッジ日時 | 2025-04-15 22:56:45 |
| 合計ジャッジ時間 | 8,241 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 15 |
ソースコード
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()
lam6er