結果

問題 No.1470 Mex Sum
ユーザー harurunharurun
提出日時 2021-04-09 22:55:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,629 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 27,220 KB
最終ジャッジ日時 2023-09-07 12:34:42
合計ジャッジ時間 9,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,428 KB
testcase_01 AC 17 ms
8,352 KB
testcase_02 AC 33 ms
9,804 KB
testcase_03 AC 32 ms
9,792 KB
testcase_04 AC 34 ms
9,656 KB
testcase_05 AC 34 ms
9,624 KB
testcase_06 AC 33 ms
9,840 KB
testcase_07 AC 33 ms
9,836 KB
testcase_08 AC 34 ms
9,724 KB
testcase_09 AC 33 ms
9,720 KB
testcase_10 AC 33 ms
9,764 KB
testcase_11 AC 33 ms
9,696 KB
testcase_12 AC 184 ms
26,724 KB
testcase_13 AC 181 ms
26,440 KB
testcase_14 AC 180 ms
26,636 KB
testcase_15 AC 184 ms
26,764 KB
testcase_16 AC 180 ms
26,544 KB
testcase_17 AC 180 ms
26,364 KB
testcase_18 AC 178 ms
26,272 KB
testcase_19 AC 180 ms
26,384 KB
testcase_20 AC 179 ms
26,432 KB
testcase_21 AC 185 ms
27,028 KB
testcase_22 AC 186 ms
27,200 KB
testcase_23 AC 186 ms
27,084 KB
testcase_24 AC 188 ms
27,112 KB
testcase_25 AC 186 ms
27,192 KB
testcase_26 AC 187 ms
27,108 KB
testcase_27 AC 186 ms
27,080 KB
testcase_28 AC 186 ms
27,072 KB
testcase_29 AC 187 ms
27,092 KB
testcase_30 AC 186 ms
27,148 KB
testcase_31 AC 186 ms
27,192 KB
testcase_32 AC 186 ms
27,220 KB
testcase_33 AC 188 ms
27,056 KB
testcase_34 AC 189 ms
27,072 KB
testcase_35 AC 187 ms
27,064 KB
testcase_36 AC 186 ms
27,200 KB
testcase_37 AC 150 ms
24,632 KB
testcase_38 AC 149 ms
24,724 KB
testcase_39 AC 152 ms
18,384 KB
testcase_40 AC 168 ms
24,780 KB
testcase_41 AC 170 ms
24,772 KB
testcase_42 AC 169 ms
24,764 KB
testcase_43 AC 169 ms
24,688 KB
testcase_44 AC 170 ms
24,664 KB
testcase_45 AC 169 ms
24,608 KB
testcase_46 AC 173 ms
24,712 KB
testcase_47 AC 168 ms
24,744 KB
testcase_48 AC 168 ms
24,708 KB
testcase_49 AC 169 ms
24,712 KB
testcase_50 AC 168 ms
24,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class INPUT:
  def __init__(self):
    self.l=open(0).read().split()[::-1]
    self.length=len(self.l)
    return

  def stream(self,k=1,f=int,f2=False):
    assert(-1<k)
    m=self.length
    if m==0 or m<k:
      raise Exception("There is no input!")
    elif f!=str:
      if k==0:
        self.length=0
        return list(map(f,self.l[::-1]))
      if k==1 and not f2:
        self.length-=1
        return f(self.l.pop())
      if k==1 and f2:
        self.length-=1
        return [f(self.l.pop())]
      ret=[]
      for _ in [0]*k:
        ret.append(f(self.l.pop()))
      self.length-=k
      return ret
    else:
      if k==0:
        self.length=0
        return self.l[::-1]
      if k==1 and not f2:
        self.length-=1
        return self.l.pop()
      if k==1 and f2:
        self.length-=1
        return [self.l.pop()]
      ret=[]
      for _ in [0]*k:
        ret.append(self.l.pop())
      self.length-=k
      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(0)
  d1=[0]
  d2=[0]
  for i in A:
    if i==1:
      d1.append(d1[-1]+1)
    else:
      d1.append(d1[-1])
    if i==2:
      d2.append(d2[-1]+1)
    else:
      d2.append(d2[-1])
  ans=0
  for i in range(N):
    s1=d1[-1]-d1[i]#1の個数
    s2=d2[-1]-d2[i]#2の個数
    t=N-i-1-s1-s2#それ以外の個数
    if A[i]==1:
      ans+=s1*2+s2*3+t*2
    elif A[i]==2:
      ans+=s1*3+s2+t
    else:
      ans+=s1*2+s2+t
  print(ans)
  return

main()

      
0