結果

問題 No.1650 Moving Coins
ユーザー harurunharurun
提出日時 2021-08-20 22:14:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 527 ms / 2,000 ms
コード長 2,242 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 105,640 KB
最終ジャッジ日時 2023-08-04 06:53:03
合計ジャッジ時間 8,575 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,388 KB
testcase_01 AC 16 ms
8,480 KB
testcase_02 AC 16 ms
8,240 KB
testcase_03 AC 19 ms
9,584 KB
testcase_04 AC 17 ms
9,180 KB
testcase_05 AC 17 ms
9,416 KB
testcase_06 AC 17 ms
9,600 KB
testcase_07 AC 17 ms
9,460 KB
testcase_08 AC 198 ms
45,828 KB
testcase_09 AC 185 ms
42,984 KB
testcase_10 AC 205 ms
47,312 KB
testcase_11 AC 209 ms
47,984 KB
testcase_12 AC 121 ms
30,760 KB
testcase_13 AC 129 ms
31,748 KB
testcase_14 AC 187 ms
42,984 KB
testcase_15 AC 109 ms
27,628 KB
testcase_16 AC 238 ms
53,220 KB
testcase_17 AC 242 ms
54,188 KB
testcase_18 AC 256 ms
57,972 KB
testcase_19 AC 344 ms
80,580 KB
testcase_20 AC 338 ms
80,500 KB
testcase_21 AC 336 ms
80,484 KB
testcase_22 AC 527 ms
105,504 KB
testcase_23 AC 519 ms
105,640 KB
testcase_24 AC 19 ms
9,812 KB
testcase_25 AC 18 ms
9,352 KB
testcase_26 AC 193 ms
53,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class INPUT:
  def __init__(self):
    self._l=open(0).read().split()
    self._length=len(self._l)
    self._index=0
    return

  def stream(self,k=1,f=int,f2=False):
    assert(-1<k)
    if self._length==self._index or self._length-self._index<k:
      raise Exception("There is no input!")
    elif f!=str:
      if k==0:
        ret=list(map(f,self._l[self._index:]))
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=f(self._l[self._index])
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[f(self._l[self._index])]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(f(self._l[self._index]))
        self._index+=1
      return ret
    else:
      if k==0:
        ret=list(self._l[self._index:])
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=self._l[self._index]
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[self._l[self._index]]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(self._l[self._index])
        self._index+=1
      return ret
pin=INPUT().stream

#pin(number[default:1],f[default:int],f2[default:False])
#if number==0 -> return left all
#listを変数で受け取るとき、必ずlistをTrueにすること。

def main():
  N=pin(1)
  A=pin(N,int,1)
  B=pin(N,int,1)
  ans=0
  ansl=[]
  C=[]
  # [L*R*] の区間でわける
  tmp=[[],[]]
  fl=-1
  for i in range(N):
    ans+=abs(A[i]-B[i])
    if A[i]==B[i]:
      if (tmp[0] or tmp[1]):
        C.append(tmp)
        tmp=[[],[]]
    elif A[i]<B[i]:
      # R
      if fl==-1:
        fl=0
      elif fl==0:
        pass
      else:
        fl=0
      tmp[1].append(i)
    else:
      # L
      if fl==-1:
        fl=1
      elif fl==1:
        pass
      else:
        fl=1
        C.append(tmp)
        tmp=[[],[]]
      tmp[0].append(i)
  if tmp[0] or tmp[1]:
    C.append(tmp)
  #print(C)
  for L,R in C:
    for i in L:
      ansl.append((f"{i+1} L\n"*(A[i]-B[i])).rstrip("\n"))
    for i in R[::-1]:
      ansl.append((f"{i+1} R\n"*(B[i]-A[i])).rstrip("\n"))
  print(ans)
  if ansl:
    print(*ansl,sep="\n")
  return

main()
0