結果

問題 No.155 生放送とBGM
ユーザー te-shte-sh
提出日時 2017-04-27 18:25:11
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,890 ms / 6,000 ms
コード長 1,115 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 155,172 KB
実行使用メモリ 56,528 KB
最終ジャッジ日時 2023-09-03 13:05:03
合計ジャッジ時間 12,375 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,870 ms
55,244 KB
testcase_01 AC 1,890 ms
55,900 KB
testcase_02 AC 1,887 ms
56,528 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 44 ms
11,832 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 344 ms
55,448 KB
testcase_07 AC 6 ms
4,388 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 10 ms
6,184 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 13 ms
7,856 KB
testcase_12 AC 15 ms
9,720 KB
testcase_13 AC 5 ms
4,388 KB
testcase_14 AC 1,384 ms
38,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;  // BitArray

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], l = rd[1] * 60;
  auto si = readln.split.map!(s => s[0..2].to!int * 60 + s[3..5].to!int).array;

  if (l >= si.sum) {
    writeln(n);
    return;
  }

  auto dp1 = new long[](n);
  
  auto calc(int t, int[] ti)
  {
    auto dp2 = BitArray();
    dp2.length = l + 1;
    dp2[0] = true;

    foreach (i; 0..n-1) {
      auto a = dp2.dup;
      a <<= ti[i];
      dp2 |= a;
    }

    auto rt = new long[][](l + 1, n);
    rt[0][0] = 1;
    foreach (i; 0..n-1)
      foreach_reverse (j; ti[i]..l+1)
        if (dp2[j - ti[i]] && dp2[j])
          rt[j][1..$][] += rt[j - ti[i]][0..$-1][];

    foreach (j; max(0, l-t)..l)
      dp1[] += rt[j][];
  }

  foreach (i; 0..n) {
    auto t = si[i], ti = si[0..i] ~ si[i+1..n];
    calc(t, ti);
  }

  real r = 0;
  foreach (i; 0..n) {
    auto a = dp1[i].to!real * (i + 1);
    foreach (j; 1..i+1) a *= j;
    foreach (j; 1..n-i) a *= j;
    r += a;
  }
  foreach (j; 1..n+1) r /= j;

  writefln("%.10f", r);
}
0