結果

問題 No.420 mod2漸化式
ユーザー te-sh
提出日時 2017-10-26 16:25:09
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 610 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 99,420 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 22:08:59
合計ジャッジ時間 1,844 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void main()
{
  auto n = 31;
  auto x = readln.chomp.to!int;

  if (x == 0) {
    writeln(1, " ", 0);
    return;
  }

  if (x > n) {
    writeln(0, " ", 0);
    return;
  }

  auto pt = pascalTriangle!int(n);
  writeln(pt[n][x], " ", long((1<<n)-1) * pt[n-1][x-1]);
}

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