結果

問題 No.155 生放送とBGM
ユーザー ctyl_0ctyl_0
提出日時 2015-11-05 15:05:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,182 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 88,392 KB
実行使用メモリ 19,868 KB
最終ジャッジ日時 2023-10-11 13:59:18
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,352 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template

double fact[51];
double dp[51][36001];
double revdp[51][36001];

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    // source code
    
    // calculate n!
    fact[0] = 1;
    repd(i, 1, 51){
        fact[i] = fact[i - 1] * i;
    }
    
    int N = inputValue(); // 50
    int L = inputValue() * 60; // second 300 * 60 = 18000
    vector<int> S(N); // second // 00:01 ~ 59:59
    int sum = 0;
    rep(i, N){
        int m, s;
        scanf("%d:%d", &m, &s);
        S[i] = m * 60 + s;
        sum += S[i];
    }
    
    if (sum <= L) {
        output(N, 0);
        return 0;
    }
    
    dp[0][0] = 1;
    rep(i, N){
        for (int j = i; j >= 0; j--) {
            for (int k = 0; S[i] + k <= 2 * L; k++) {
                if (dp[j][k]){
                    dp[j + 1][min(2 * L, k + S[i])] += dp[j][k];
                }
            }
        }
    }
    
    // 戻すDP
    double ret = 0;
    
    rep(i, N){
        rep(j, N){
            for (int k = 0; k < L + S[i]; k++) {
                revdp[j][k] = dp[j][k];
                if (k - S[i] >= 0 && j) revdp[j][k] -= revdp[j - 1][k - S[i]];
                // if(revdp[j][k]) cout << "revdp[" << j << "][" << k << "] = " << revdp[j][k] << endl;
                if (k < L) ret += revdp[j][k] * fact[j] * fact[N - j - 1];
            }
        }
        
    }
    
    // output(ret, 0);
    ret /= fact[N];
    double ans = 0;
    ans += ret;
    
    output(ans, 15);
    return 0;
}
0