結果

問題 No.1650 Moving Coins
ユーザー O2MTO2MT
提出日時 2021-08-20 22:36:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 193,180 KB
最終ジャッジ日時 2024-04-22 05:26:17
合計ジャッジ時間 23,156 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,400 KB
testcase_01 AC 51 ms
54,400 KB
testcase_02 AC 44 ms
54,272 KB
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 WA -
testcase_19 AC 1,321 ms
152,660 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1,336 ms
153,468 KB
testcase_23 AC 1,348 ms
153,376 KB
testcase_24 AC 147 ms
98,944 KB
testcase_25 AC 164 ms
99,200 KB
testcase_26 AC 1,194 ms
132,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
from collections import deque

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort()
for i in range(N):
  A[i] = (-A[i],'A',i+1)
B.sort()
for i in range(N):
  B[i] = (-B[i],'B',i+1)
C = A+B
C.sort()
ans_list = []
la,lb = 0,0
que_a,que_b = deque([]),deque([])

while C:
  n1,c1,i1 = heappop(C)
  n2,c2,i2 = heappop(C)
  n1 *= -1
  n2 *= -1
  if c1 != c2:
    s = ''
    i = 0
    num = abs(n1-n2)
    if c1 == 'A':
      i = i1
      if n1 < n2:
        s = 'R'
      if n1 > n2:
        s = 'L'
    if c1 == 'B':
      i = i2
      if n1 < n2:
        s = 'L'
      if n1 > n2:
        s = 'R'
    if s != '':
      for _ in range(num):
        ans_list.append((i,s))
  else:
    if c1 == 'A':
      que_a.append((n1,i1))
      que_a.append((n2,i2))
      la += 2
    else:
      que_b.append((n1,i1))
      que_b.append((n2,i2))
      lb += 2
    
    if la == lb:
      while que_a:
        n1,i1 = que_a.pop()
        n2,i2 = que_b.pop()
        num = abs(n1-n2)
        s = ''
        if n1 < n2:
          s = 'R'
        else:
          s = 'L'
        for _ in range(num):
          ans_list.append((i1,s))


print(len(ans_list))
for x,y in ans_list:
  print(x,y)
0