結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー とりゐとりゐ
提出日時 2021-12-21 19:29:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 80,500 KB
最終ジャッジ日時 2023-10-14 13:54:16
合計ジャッジ時間 11,374 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,288 KB
testcase_01 AC 77 ms
71,488 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 140 ms
78,836 KB
testcase_19 AC 120 ms
77,940 KB
testcase_20 AC 150 ms
79,408 KB
testcase_21 AC 121 ms
77,808 KB
testcase_22 AC 156 ms
79,108 KB
testcase_23 AC 160 ms
78,960 KB
testcase_24 AC 164 ms
79,448 KB
testcase_25 AC 168 ms
79,324 KB
testcase_26 AC 165 ms
79,132 KB
testcase_27 AC 163 ms
79,132 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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,0))
      a[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]

print(len(operation))
for t,p,q in operation:
  print(t,p+1,q+1)
0