結果

問題 No.155 生放送とBGM
ユーザー parukiparuki
提出日時 2016-09-06 14:17:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 6,000 ms
コード長 1,690 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 168,404 KB
実行使用メモリ 20,960 KB
最終ジャッジ日時 2023-08-09 22:27:00
合計ジャッジ時間 3,520 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
20,956 KB
testcase_01 AC 175 ms
20,876 KB
testcase_02 AC 163 ms
20,960 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 11 ms
10,240 KB
testcase_05 AC 3 ms
7,168 KB
testcase_06 AC 190 ms
20,940 KB
testcase_07 AC 8 ms
14,720 KB
testcase_08 AC 6 ms
11,148 KB
testcase_09 AC 10 ms
14,944 KB
testcase_10 AC 5 ms
10,612 KB
testcase_11 AC 12 ms
18,416 KB
testcase_12 AC 13 ms
15,760 KB
testcase_13 AC 6 ms
10,836 KB
testcase_14 AC 138 ms
20,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template <class Val>
vector<Val> factorials(int n){
    vector<Val> res(n + 1);
    res[0] = res[1] = 1;
    for(int i = 2; i <= n; ++i)
        res[i] = res[i - 1] * i;
    return res;
}

int N, L;
const int HI = 300 * 60 + 60 * 60 + 1;
double adp[HI][51], bdp[HI][51];

int main(){
    cin >> N >> L;
    L *= 60;
    vi S(N);
    int sm = 0;
    rep(i, N){
        int m, s;
        scanf("%d:%d", &m, &s);
        S[i] = m * 60 + s;
        sm += S[i];
    }
    if(sm <= L){
        cout << N << endl;
        return 0;
    }

    adp[0][0] = 1;
    rep(i, N){
        for(int t = L+S[i]-1; t >= S[i]; --t){
            for(int x = i+1; x >= 1; --x){
                adp[t][x] += adp[t - S[i]][x - 1];
            }
        }
    }

    auto F = factorials<double>(N);

    double ans = 0;
    rep(i, N){
        rep(t, L + S[i]){
            rep(x, N + 1){
                bdp[t][x] = adp[t][x];
                if(t >= S[i] && x > 0){
                    bdp[t][x] -= bdp[t - S[i]][x - 1];
                }
                if(t < L && x<N)ans += bdp[t][x] * F[x] * F[N - x - 1];
            }
        }
    }
    ans /= F[N];
    cout << setprecision(20) << ans << endl;
}
0