結果

問題 No.1701 half price
ユーザー harurunharurun
提出日時 2021-02-21 22:46:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,745 ms / 3,000 ms
コード長 1,901 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 76,932 KB
最終ジャッジ日時 2023-09-30 09:22:02
合計ジャッジ時間 7,347 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
70,892 KB
testcase_01 AC 78 ms
76,240 KB
testcase_02 AC 236 ms
76,628 KB
testcase_03 AC 80 ms
75,980 KB
testcase_04 AC 235 ms
76,560 KB
testcase_05 AC 89 ms
76,236 KB
testcase_06 AC 1,717 ms
76,932 KB
testcase_07 AC 1,745 ms
76,752 KB
testcase_08 AC 74 ms
70,548 KB
testcase_09 AC 81 ms
76,040 KB
testcase_10 AC 70 ms
70,756 KB
testcase_11 AC 71 ms
70,884 KB
testcase_12 AC 71 ms
70,520 KB
testcase_13 AC 77 ms
70,884 KB
testcase_14 AC 78 ms
70,948 KB
testcase_15 AC 77 ms
70,824 KB
testcase_16 AC 77 ms
70,820 KB
testcase_17 AC 78 ms
70,744 KB
testcase_18 AC 80 ms
70,816 KB
testcase_19 AC 79 ms
70,892 KB
testcase_20 AC 78 ms
70,984 KB
testcase_21 AC 80 ms
70,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class INPUT:
  def __init__(self):
    from sys import argv
    if argv[-1] in ["./Main.py","prog.py","Main.py"]:#Atcoder:./Main.py,Wandbox:prog.py,yukicoder:Main.py
      self.l=open(0).read().split()[::-1]
    else:
      self.l=open("_input.txt",mode="r").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

def change(n,k):
  ret=""
  while n!=0:
    ret+=str(n%k)
    n//=k
  return ret

def main():
  N,W=pin(2)
  assert(1<=N<=13)
  assert(0<=W<=pow(10,9))
  a=pin(0)
  for i in a:
    assert(0<=i<=pow(10,9))
    debug=i%2
    assert(debug==0)
  cnt_0=a.count(0)
  n=N-cnt_0
  A=list(filter(lambda x:x!=0,a))
  if W==0:
    return print(pow(2,cnt_0)-1)#何も選ばないことはできない
  ans=set()
  B=[i//2 for i in A]
  for i in range(3**n):
    s=0
    b=""
    u=change(i,3).ljust(N,"0")
    for j in range(n):
      if u[j]=="1":
        s+=A[j]
        b+="1"
      elif u[j]=="2":
        s+=B[j]
        b+="1"
      else:
        b+="0"
    if s==W:
      ans.add(b)
  print(len(ans)*pow(2,cnt_0))
  return

main()

0