結果

問題 No.155 生放送とBGM
ユーザー te-shte-sh
提出日時 2017-04-27 18:18:10
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,105 bytes
コンパイル時間 2,539 ms
コンパイル使用メモリ 155,184 KB
実行使用メモリ 25,832 KB
最終ジャッジ日時 2023-09-03 13:04:25
合計ジャッジ時間 9,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,384 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 304 ms
24,168 KB
testcase_07 AC 6 ms
4,388 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 9 ms
4,600 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 11 ms
4,600 KB
testcase_12 AC 13 ms
4,404 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 WA -
権限があれば一括ダウンロードができます

ソースコード

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 int[](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 int[][](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; 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