結果

問題 No.155 生放送とBGM
ユーザー eitahoeitaho
提出日時 2015-02-18 23:09:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,997 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 145,672 KB
最終ジャッジ日時 2023-09-06 02:13:03
合計ジャッジ時間 5,104 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,736 KB
testcase_06 AC 1,130 ms
145,652 KB
testcase_07 AC 4 ms
13,952 KB
testcase_08 AC 3 ms
7,716 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 7 ms
22,152 KB
testcase_13 AC 5 ms
15,852 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <climits>
#include <numeric>
#include <functional>
#include <time.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; i++)
template<class T> void checkmin(T &a, T b) { if (b < a) a = b; }
template<class T> void checkmax(T &a, T b) { if (b > a) a = b; }

const int MaxN = 50;
//const int MaxL = 300 * 60;
const int MaxSec = 60 * 60;
int N, L;
int Sec[MaxN];
ll dp[MaxN + 1][MaxSec * MaxN + 1];
ll others[MaxN + 1][MaxSec * MaxN + 1];
int sumSec[MaxN];
double fact[MaxN + 1];


void solve() {
    for (int i = 0; i < N; i++) sumSec[i] = Sec[i] + (i > 0 ? sumSec[i - 1] : 0);
    if (sumSec[N - 1] <= L) { cout << N << endl; return; }

    fact[0] = 1;
    for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i;
    dp[0][0] = others[0][0] = 1;
    rep(i, N) for (int used = i; used >= 0; used--) FOR(len, 0, sumSec[i] - Sec[i]) {
        dp[used + 1][len + Sec[i]] += dp[used][len];
    }

    double ans = 0;
    for (int i = 0; i < N; i++) {
        double good = fact[N - 1];
        for (int used = 1; used < N; used++)
        for (int len = 0; len <= sumSec[N - 1]; len++) {
            others[used][len] = dp[used][len];
            if (len >= Sec[i]) others[used][len] -= others[used - 1][len - Sec[i]];
            if (len < L && others[used][len] > 0) good += others[used][len] * fact[used] * fact[N - used - 1];
        }
        good /= fact[N];
        ans += good;
    }

    cout << ans << endl;
}

int main() {
    cin >> N >> L;
    L *= 60;
    rep(i, N) {
        int m, s;
        scanf("%d:%d", &m, &s);
        Sec[i] = m * 60 + s;
    }
    solve();
    return 0;
}
0