結果

問題 No.1457 ツブ消ししとるなHard
ユーザー mkawa2
提出日時 2021-03-31 22:09:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,522 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 848,660 KB
最終ジャッジ日時 2024-12-15 19:09:54
合計ジャッジ時間 11,047 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

from collections import defaultdict

n,m,x,y,z=LI()
aa0=LI()
s=0
cnt=0
aa=[]

for a in aa0:
    if a<=y:continue
    if a>=x:
        s+=a-z
        cnt+=1
    else:
        aa.append(a-z)

if cnt>m:
    print("Handicapped")
    exit()

m-=cnt
s=-s
n=len(aa)

def tos(aa):
    res=[(0,0)]
    for a in aa:
        nres=[]
        for s,c in res:
            if c+1<=m:nres.append((s+a,c+1))
        res+=nres

    dic=defaultdict(list)
    for s,c in res:dic[s].append(c)

    return dic

pre=tos(aa[:n//2])
pos=tos(aa[n//2:])
# print(s,m,pre,pos)

ans=0
for s0,cc0 in pre.items():
    s1=s-s0
    if s1 in pos:
        cc0.sort()
        cc1=sorted(pos[s1])
        j=len(cc1)-1
        for c in cc0:
            while j>=0 and cc1[j]+c>m:j-=1
            if j<0:break
            ans+=j+1

if s==0:ans-=1
print(ans)
0