結果

問題 No.155 生放送とBGM
ユーザー tsutajtsutaj
提出日時 2018-02-07 20:24:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 497 ms / 6,000 ms
コード長 1,405 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 44,676 KB
実行使用メモリ 18,892 KB
最終ジャッジ日時 2023-10-18 22:39:40
合計ジャッジ時間 3,278 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
18,836 KB
testcase_01 AC 292 ms
18,884 KB
testcase_02 AC 161 ms
18,892 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 13 ms
13,600 KB
testcase_05 AC 2 ms
5,324 KB
testcase_06 AC 497 ms
18,792 KB
testcase_07 AC 3 ms
7,624 KB
testcase_08 AC 3 ms
5,396 KB
testcase_09 AC 4 ms
9,788 KB
testcase_10 AC 3 ms
7,464 KB
testcase_11 AC 5 ms
9,912 KB
testcase_12 AC 5 ms
9,872 KB
testcase_13 AC 3 ms
7,536 KB
testcase_14 AC 244 ms
18,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int N, L, S[60];
long long int dp[60][18010];
long long int dp2[60][18010];

int main() {
    scanf("%d%d", &N, &L); L *= 60;

    int sum = 0;
    for(int i=0; i<N; i++) {
        int m, s; scanf("%d:%d", &m, &s);
        S[i] = 60*m + s;
        sum += S[i];
    }

    if(sum <= L) {
        printf("%.12f\n", (double)N);
        return 0;
    }

    dp[0][0] = 1;
    for(int i=0; i<N; i++) {
        for(int j=i; j>=0; j--) {
            for(int k=0; k<=L; k++) {
                if(k - S[i] >= 0) dp[j+1][k] += dp[j][k - S[i]];
            }
        }
    }

    double ans = 0.0;
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            for(int l=0; l<L; l++) {
                dp2[j][l] = dp[j][l];
                if(j > 0 && l-S[i] >= 0) dp2[j][l] -= dp2[j-1][l-S[i]];
                long long int pat = dp2[j][l];

                if(L-S[i]<=l) {
                    int X = j, Y = N-j-1;

                    // combination
                    double b = 1;
                    for(int k=1; k<=min(X,Y); k++) {
                        b *= (N - k);
                        b /= k;
                    }
                    b *= N;
                    b = ((X+1) * pat) / b;
                    ans += b;
                }
            }
        }
    }
    printf("%.12f\n", ans);
    return 0;
}
0