結果

問題 No.1701 half price
ユーザー harurunharurun
提出日時 2021-06-26 10:43:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,008 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 276,528 KB
最終ジャッジ日時 2023-09-30 09:23:27
合計ジャッジ時間 6,125 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,704 KB
testcase_01 AC 21 ms
9,064 KB
testcase_02 AC 137 ms
23,912 KB
testcase_03 AC 21 ms
8,924 KB
testcase_04 AC 408 ms
57,164 KB
testcase_05 AC 25 ms
9,376 KB
testcase_06 AC 755 ms
80,416 KB
testcase_07 TLE -
testcase_08 AC 22 ms
8,744 KB
testcase_09 AC 21 ms
8,848 KB
testcase_10 AC 21 ms
8,964 KB
testcase_11 AC 21 ms
8,792 KB
testcase_12 AC 23 ms
8,900 KB
testcase_13 AC 22 ms
8,856 KB
testcase_14 AC 21 ms
8,864 KB
testcase_15 AC 21 ms
8,824 KB
testcase_16 AC 21 ms
8,748 KB
testcase_17 AC 21 ms
8,788 KB
testcase_18 AC 21 ms
8,804 KB
testcase_19 AC 21 ms
8,932 KB
testcase_20 AC 21 ms
8,708 KB
testcase_21 AC 360 ms
37,068 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

"""
pin(number[default:1],f[default:int],f2[default:False])
if number==0 -> return left all
eclipse 等では_input.txtを使うこと。
listを変数で受け取るとき、必ずlistをTrueにすること。
"""
from functools import lru_cache
from collections import Counter
from sys import setrecursionlimit
setrecursionlimit(10000000)

N,W=pin(2)
A=pin(0)
if W==0 and A==[0]*N:
  exit(print(pow(2,N)-1))
n=pow(2,N)
b=[[Counter()for __ in [0]*n]for _ in [0]*N]
cnt=[[Counter()for __ in [0]*n]for _ in [0]*N]
f=[pow(2,i)for i in range(N)]
@lru_cache(maxsize=10000000)
def rec(m,w,d):
  if m==0:
    if w==0:
      #print(d)
      return set([d])
    else:
      return set([0])
  return rec(m-1,w-A[m-1],d+f[m-1])|rec(m-1,w-A[m-1]//2,d+f[m-1])|rec(m-1,w,d)
ans=rec(N,W,0)
#print(ans)
print(len(ans)-1)
# for i in cnt:
#   print(i)
0