結果

問題 No.1701 half price
ユーザー harurunharurun
提出日時 2021-02-27 10:59:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,367 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 11,024 KB
実行使用メモリ 231,176 KB
最終ジャッジ日時 2023-09-30 09:23:20
合計ジャッジ時間 6,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,800 KB
testcase_01 AC 21 ms
9,012 KB
testcase_02 AC 147 ms
21,808 KB
testcase_03 AC 22 ms
8,888 KB
testcase_04 AC 450 ms
47,748 KB
testcase_05 AC 25 ms
9,376 KB
testcase_06 AC 819 ms
71,560 KB
testcase_07 TLE -
testcase_08 AC 20 ms
8,744 KB
testcase_09 AC 21 ms
9,060 KB
testcase_10 AC 19 ms
8,928 KB
testcase_11 AC 20 ms
8,988 KB
testcase_12 AC 21 ms
8,828 KB
testcase_13 AC 21 ms
8,768 KB
testcase_14 AC 20 ms
8,864 KB
testcase_15 AC 21 ms
8,944 KB
testcase_16 AC 20 ms
8,760 KB
testcase_17 AC 20 ms
8,780 KB
testcase_18 AC 20 ms
8,752 KB
testcase_19 AC 20 ms
8,872 KB
testcase_20 AC 20 ms
8,860 KB
testcase_21 AC 395 ms
39,180 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 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)]
def rec(m,w,d):
  if m==0:
    if w==0:
      #print(d)
      return set([d])
    else:
      return set([0])
#   if b[m-1][0][w-A[m-1]]==0:
#     r1=set()
#     #if w-A[m-1]>=0:
#     r1=rec(m-1,w-A[m-1],d+pow(2,m-1))
#     #print(type(r1))
#     cnt[m-1][0][w-A[m-1]]=r1
#     b[m-1][0][w-A[m-1]]=1
#
#   if b[m-1][1][w-A[m-1]//2]==0:
#     r2=set()
#     #if w-A[m-1]//2>=0:
#     r2=rec(m-1,w-A[m-1]//2,d+pow(2,m-1))
#     #print(type(r2))
#     cnt[m-1][1][w-A[m-1]//2]=r2
#     b[m-1][1][w-A[m-1]//2]=1
#   if b[m-1][2][w]==0:
#     r3=rec(m-1,w,d)
#     #print(type(r3))
#     cnt[m-1][2][w]=r3
#     b[m-1][2][w]=1
#   if 0 in [cnt[m-1][0][w-A[m-1]],cnt[m-1][1][w-A[m-1]//2],cnt[m-1][2][w]]:
#     print(cnt[m-1][0][w-A[m-1]],cnt[m-1][1][w-A[m-1]//2],cnt[m-1][2][w])
#     print(b[m-1][0][w-A[m-1]],b[m-1][1][w-A[m-1]//2],b[m-1][2][w])
#     print(m,w,d)
#     raise Exception
  #print(cnt[m-1][w-A[m-1]],cnt[m-1][w-A[m-1]//2],cnt[m-1][w])
  #print(type(cnt[m-1][w-A[m-1]]),type(cnt[m-1][w-A[m-1]//2]),type(cnt[m-1][w]))
  #return cnt[m-1][0][w-A[m-1]]|cnt[m-1][1][w-A[m-1]//2]|cnt[m-1][2][w]
  if b[m-1][d+f[m-1]][w-A[m-1]]==0:
    b[m-1][d+f[m-1]][w-A[m-1]]=1
    cnt[m-1][d+f[m-1]][w-A[m-1]]=rec(m-1,w-A[m-1],d+f[m-1])
  if b[m-1][d+f[m-1]][w-A[m-1]//2]==0:
    b[m-1][d+f[m-1]][w-A[m-1]//2]=1
    cnt[m-1][d+f[m-1]][w-A[m-1]//2]=rec(m-1,w-A[m-1]//2,d+f[m-1])
  if b[m-1][d][w]==0:
    b[m-1][d][w]=1
    cnt[m-1][d][w]=rec(m-1,w,d)
  return cnt[m-1][d+f[m-1]][w-A[m-1]]|cnt[m-1][d+f[m-1]][w-A[m-1]//2]|cnt[m-1][d][w]
 # 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