結果

問題 No.155 生放送とBGM
ユーザー te-shte-sh
提出日時 2018-07-12 17:11:03
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 489 ms / 6,000 ms
コード長 1,288 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 153,348 KB
実行使用メモリ 385,724 KB
最終ジャッジ日時 2023-09-03 20:42:43
合計ジャッジ時間 5,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 477 ms
385,316 KB
testcase_01 AC 475 ms
385,324 KB
testcase_02 AC 474 ms
385,280 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 22 ms
18,672 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 489 ms
385,724 KB
testcase_07 AC 4 ms
6,116 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 7 ms
6,764 KB
testcase_10 AC 3 ms
5,032 KB
testcase_11 AC 9 ms
8,136 KB
testcase_12 AC 10 ms
9,452 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 364 ms
294,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, l; readV(n, l);
  string[] st; readA(n, st);

  l *= 60;
  auto s = st.map!(sti => sti[0..2].to!int*60+sti[3..5].to!int).array;

  if (s.sum < l) {
    writeln(n);
    return;
  }

  auto dp1 = new long[][][](n+1, n+1, l); dp1[0][0][0] = 1;
  foreach (i; 0..n)
    foreach (j; 0..n+1)
      foreach (k; 0..l) {
        dp1[i+1][j][k] = dp1[i][j][k];
        if (j >= 1 && k >= s[i])
          dp1[i+1][j][k] += dp1[i][j-1][k-s[i]];
      }

  auto fact = new real[](n+1); fact[0] = 1;
  foreach (i; 1..n+1) fact[i] = fact[i-1]*i;

  auto r = 0.0L, dp2 = new long[][](n+1, l);
  foreach (i; 0..n) {
    foreach (j; 0..n+1)
      foreach (k; 0..l) {
        dp2[j][k] = dp1[n][j][k];
        if (j >= 1 && k >= s[i])
          dp2[j][k] -= dp2[j-1][k-s[i]];
      }

    foreach (j; 0..n)
      foreach (k; max(0, l-s[i])..l)
        r += dp2[j][k]*fact[j+1]*fact[n-1-j];
  }

  writefln("%.10f", r/fact[n]);
}
0