結果

問題 No.472 平均順位
ユーザー lam6er
提出日時 2025-03-20 21:08:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,697 ms / 2,000 ms
コード長 1,513 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 81,924 KB
実行使用メモリ 90,904 KB
最終ジャッジ日時 2025-03-20 21:09:22
合計ジャッジ時間 10,047 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    P = int(input[idx])
    idx += 1
    a_list = []
    b_list = []
    c_list = []
    for _ in range(N):
        a = int(input[idx])
        idx += 1
        b = int(input[idx])
        idx += 1
        c = int(input[idx])
        idx += 1
        a_list.append(a)
        b_list.append(b)
        c_list.append(c)
    
    INF = float('inf')
    current = [INF] * (P + 1)
    current[0] = 0.0
    
    for i in range(N):
        a = a_list[i]
        b = b_list[i]
        c = c_list[i]
        remaining = (N - 1) - i  # Remaining contests after this one
        min_s_new = max(0, P - 3 * remaining)
        next_dp = [INF] * (P + 1)
        
        for s_prev in range(P + 1):
            if current[s_prev] == INF:
                continue
            for x in 0, 1, 2, 3:
                s_new = s_prev + x
                if s_new > P:
                    continue
                if s_new < min_s_new:
                    continue
                if x == 3:
                    rank = 1
                elif x == 0:
                    rank = a
                elif x == 1:
                    rank = b
                else:
                    rank = c
                if current[s_prev] + rank < next_dp[s_new]:
                    next_dp[s_new] = current[s_prev] + rank
        current = next_dp
    
    print("{0:.10f}".format(current[P] / N))

if __name__ == '__main__':
    main()
0