結果

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

ソースコード

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 sorted(dic.items(),key=lambda x:x[0])

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

ans=0
i=len(pos)-1
for s0,cc0 in pre:
    while i>=0 and pos[i][0]+s0>s:
        i-=1
    if i<0:break
    if pos[i][0]+s0==s:
        cc0.sort()
        cc1=sorted(pos[i][1])
        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