結果

問題 No.155 生放送とBGM
ユーザー tsutajtsutaj
提出日時 2018-02-07 20:10:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,582 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 45,180 KB
実行使用メモリ 28,612 KB
最終ジャッジ日時 2023-10-18 22:14:13
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 415 ms
28,612 KB
testcase_01 AC 407 ms
28,612 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 48 ms
28,612 KB
testcase_05 AC 7 ms
20,344 KB
testcase_06 AC 612 ms
28,612 KB
testcase_07 AC 12 ms
28,612 KB
testcase_08 AC 9 ms
28,612 KB
testcase_09 AC 15 ms
28,612 KB
testcase_10 AC 11 ms
28,612 KB
testcase_11 AC 16 ms
28,612 KB
testcase_12 AC 17 ms
28,612 KB
testcase_13 AC 13 ms
28,612 KB
testcase_14 AC 337 ms
28,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N, L, S[60];
long long int dp[2][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][0] = 1;
    for(int i=0; i<N; i++) {
        int cur = i%2, nxt = cur^1;
        for(int j=0; j<=i; j++) {
            for(int k=0; k<=L; k++) {
                dp[nxt][j][k] += dp[cur][j][k];
                if(k - S[i] >= 0) dp[nxt][j+1][k] += dp[cur][j][k - S[i]];
            }
        }
        memset(dp[cur], 0, sizeof(dp[cur]));
    }

    double ans = 0.0;
    for(int i=0; i<N; i++) {
        memset(dp2, 0, sizeof(dp2));
        for(int j=0; j<N; j++) {
            for(int l=0; l<L; l++) {
                dp2[j][l] = dp[N%2][j][l];
                if(j > 0 && l-S[i] >= 0) dp2[j][l] -= dp2[j-1][l-S[i]];
                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