結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー ShirotsumeShirotsume
提出日時 2021-12-21 23:09:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,465 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 80,296 KB
最終ジャッジ日時 2024-04-16 12:43:33
合計ジャッジ時間 7,450 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

c=sorted(a+b)
b_min=c[n]
operation=[]

cnt=2*n
for i in range(2*n):
  if c[i]==b_min:
    cnt=min(i,cnt)

cnt=n-cnt

idx=-1
for i in range(n):
  if a[i]==b_min:
    idx=i

if idx==-1:
  idx2=-1
  for i in range(n):
    if b[i]==b_min:
      idx2=i
  operation.append((1,0,idx2))
  operation.append((2,0,idx2))
  operation.append((1,0,idx2))
  b[idx2],a[0]=a[0],b[idx2]
  idx=0

for i in range(n):
  if b[i]==b_min:
    if cnt>0:
      operation.append((2,idx,i))
      b[i]=0
      cnt-=1

idx=-1
for i in range(n):
  if b[i]==b_min:
    idx=i

if idx==-1:
  idx2=-1
  for i in range(n):
    if a[i]==b_min:
      idx2=i
  operation.append((2,idx2,0))
  operation.append((1,idx2,0))
  operation.append((2,idx2,0))
  a[idx2],b[0]=b[0],a[idx2]
  idx=0

for i in range(n):
  if a[i]==b_min:
    if cnt>0:
      operation.append((1,i,idx))
      a[i]=0
      cnt-=1

hq1=[]
for i in range(n):
  heapq.heappush(hq1,(-a[i],i))

hq2=[]
for i in range(n):
  heapq.heappush(hq2,(b[i],i))

while -hq1[0][0]>b_min:
  x,p=heapq.heappop(hq1)
  y,q=heapq.heappop(hq2)
  operation.append((1,p,q))
  operation.append((2,p,q))
  operation.append((1,p,q))
  a[p],b[q]=b[q],a[p]

for i in range(n):
    for j in range(n):
        if a[i] >= b[j]:
            print(a)
            print(b)
            raise Exception
'''
print(len(operation))
for t,p,q in operation:
  print(t,p+1,q+1)
'''
0