結果

問題 No.1457 ツブ消ししとるなHard
ユーザー mkawa2mkawa2
提出日時 2021-03-31 22:09:57
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,522 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 848,200 KB
最終ジャッジ日時 2024-05-09 08:05:51
合計ジャッジ時間 3,169 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
54,600 KB
testcase_01 AC 34 ms
53,800 KB
testcase_02 AC 34 ms
54,924 KB
testcase_03 AC 35 ms
54,904 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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