結果

問題 No.1457 ツブ消ししとるなHard
ユーザー 小野寺健小野寺健
提出日時 2021-05-01 10:36:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,041 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 11,076 KB
実行使用メモリ 41,264 KB
最終ジャッジ日時 2023-09-26 23:44:45
合計ジャッジ時間 6,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,212 KB
testcase_01 AC 17 ms
8,324 KB
testcase_02 AC 17 ms
8,160 KB
testcase_03 AC 17 ms
8,320 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 AC 16 ms
8,152 KB
testcase_08 AC 16 ms
8,236 KB
testcase_09 AC 118 ms
9,300 KB
testcase_10 AC 79 ms
8,904 KB
testcase_11 AC 20 ms
8,188 KB
testcase_12 AC 376 ms
12,748 KB
testcase_13 AC 166 ms
9,752 KB
testcase_14 AC 20 ms
8,116 KB
testcase_15 AC 217 ms
10,264 KB
testcase_16 AC 719 ms
15,400 KB
testcase_17 AC 16 ms
8,356 KB
testcase_18 AC 17 ms
8,164 KB
testcase_19 AC 1,587 ms
24,348 KB
testcase_20 AC 17 ms
8,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

N, M, X, Y, Z = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

remove = bisect.bisect_left(A, Y+1)
remain = bisect.bisect_left(A, X)
n = remain - remove
remainSum = sum(A[remain:])
remainN = N - remain

if remainN > M:
    print("Handicapped")
elif n == 0:
    if remainSum == remainN * Z:
        print(1)
    else:
        print(0)
else:
    B = A[remove:remain]
    minM = 0 if remainN > 0 else 1
    maxM = M - remainN
    maxSum = Z * M
    dp = [[[0] * (maxSum+1) for _ in range(maxM+1)] for _ in range(n)]
    dp[0][0][0] = 1
    if B[0] <= maxSum:
        dp[0][1][B[0]] = 1
    for i in range(n-1):
        for j in range(maxM+1):
            for k in range(maxSum+1):
                dp[i+1][j][k] += dp[i][j][k]
                if j+1 <= maxM and k+B[i+1] <= maxSum:
                    dp[i+1][j+1][k+B[i+1]] += dp[i][j][k];
    cnt = 0
    for j in range(minM, maxM+1):
        k = Z*(j+remainN)-remainSum
        if k >= 0 and k <= maxSum:
            cnt += dp[n-1][j][k]
    print(cnt)
0