結果

問題 No.398 ハーフパイプ(2)
ユーザー te-shte-sh
提出日時 2017-07-27 16:04:28
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 92,092 KB
実行使用メモリ 5,924 KB
最終ジャッジ日時 2023-09-03 15:33:43
合計ジャッジ時間 2,333 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
5,172 KB
testcase_01 AC 26 ms
5,856 KB
testcase_02 AC 26 ms
5,852 KB
testcase_03 AC 25 ms
5,608 KB
testcase_04 AC 25 ms
5,084 KB
testcase_05 AC 25 ms
4,836 KB
testcase_06 AC 26 ms
5,860 KB
testcase_07 AC 25 ms
4,852 KB
testcase_08 AC 26 ms
5,440 KB
testcase_09 AC 26 ms
5,644 KB
testcase_10 AC 25 ms
4,376 KB
testcase_11 AC 26 ms
4,872 KB
testcase_12 AC 26 ms
5,388 KB
testcase_13 AC 26 ms
5,924 KB
testcase_14 AC 26 ms
5,680 KB
testcase_15 AC 26 ms
5,640 KB
testcase_16 AC 26 ms
5,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const combi = pascalTriangle!int(6);

void main()
{
  auto x = (readln.chomp.to!real * 4).to!int;

  auto dp = new long[][][](101, 5, 401);
  foreach (i; 0..101) {
    dp[i][0][0] = 1;
    foreach (j; 1..5)
      foreach (k; 1..401)
        foreach (m; 1..i+1)
          if (k >= m)
            dp[i][j][k] += dp[i][j-1][k-m];
  }

  auto r = 0L;
  foreach (i; 0..100)
    foreach (j; i+1..101)
      foreach (ni; 1..6)
        foreach (nj; 1..7-ni) {
          auto m = 6 - ni - nj;
          auto y = x - (ni - 1) * i - (nj - 1) * j - m * i;
          if (y < 0) continue;
          r += dp[j - i - 1][m][y] * combi[6][ni] * combi[6-ni][nj];
        }

  if (x % 4 == 0) ++r;

  writeln(r);
}

pure T[][] pascalTriangle(T)(size_t n)
{
  auto t = new T[][](n + 1);
  t[0] = new T[](1);
  t[0][0] = 1;
  foreach (i; 1..n+1) {
    t[i] = new T[](i + 1);
    t[i][0] = t[i][$-1] = 1;
    foreach (j; 1..i)
      t[i][j] = t[i - 1][j - 1] + t[i - 1][j];
  }
  return t;
}
0