結果

問題 No.155 生放送とBGM
ユーザー ayaoniayaoni
提出日時 2021-05-09 06:47:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,406 ms / 6,000 ms
コード長 1,524 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 280,124 KB
最終ジャッジ日時 2023-10-17 15:57:37
合計ジャッジ時間 9,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,389 ms
259,828 KB
testcase_01 AC 1,406 ms
259,828 KB
testcase_02 AC 1,401 ms
259,904 KB
testcase_03 AC 39 ms
53,480 KB
testcase_04 AC 126 ms
77,544 KB
testcase_05 AC 39 ms
53,484 KB
testcase_06 AC 1,406 ms
259,828 KB
testcase_07 AC 72 ms
73,004 KB
testcase_08 AC 74 ms
72,984 KB
testcase_09 AC 84 ms
77,312 KB
testcase_10 AC 69 ms
70,880 KB
testcase_11 AC 88 ms
77,836 KB
testcase_12 AC 92 ms
78,392 KB
testcase_13 AC 70 ms
72,916 KB
testcase_14 AC 1,245 ms
280,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,L = MI()
L *= 60
S = LS()

songs = [0]  # 1-index
for s in S:
    m,s = map(int,s.split(':'))
    songs.append(60*m+s)

if sum(songs) <= L:
    print(N)
    exit()

dp = [[0]*L for _ in range(N+1)]
# dp[i][j][k] = 1~i曲目からj曲選んで、合計再生時間k分となる組み合わせ
# メモリ節約のため、i省略
dp[0][0] = 1
for i in range(1,N+1):
    s = songs[i]
    for j in range(i,-1,-1):
        for k in range(L-1,-1,-1):
            if j >= 1 and k >= s:
                dp[j][k] += dp[j-1][k-s]

fac = [1]
for i in range(1,N+1):
    fac.append(fac[-1]*i)

# 戻すdp

ans = 0
for i in range(1,N+1):
    dp2 = [[0]*L for _ in range(N+1)]
    # dp2[j][k] = i曲目以外のj曲選んで、合計再生時間k分となる組み合わせ
    s = songs[i]
    for j in range(N+1):
        coefficient = fac[j]*fac[N-j-1]/fac[N]
        for k in range(L):
            if j >= 1 and k >= s:
                dp2[j][k] = dp[j][k]-dp2[j-1][k-s]
            else:
                dp2[j][k] = dp[j][k]

            ans += dp2[j][k]*coefficient

print(ans)
0