結果

問題 No.520 プロジェクトオイラーへの招待
ユーザー Min_25Min_25
提出日時 2017-05-29 00:26:05
言語 Python2
(2.7.18)
結果
AC  
実行時間 93 ms / 4,000 ms
コード長 826 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 7,152 KB
実行使用メモリ 19,928 KB
最終ジャッジ日時 2023-10-21 14:50:47
合計ジャッジ時間 1,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
9,632 KB
testcase_01 AC 20 ms
9,632 KB
testcase_02 AC 20 ms
9,632 KB
testcase_03 AC 67 ms
17,588 KB
testcase_04 AC 93 ms
19,928 KB
testcase_05 AC 61 ms
17,264 KB
testcase_06 AC 21 ms
9,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def memoize(f):
  cache = {}
  def helper(*args):
    if args not in cache:
      cache[args] = f(*args)
    return cache[args]
  return helper

def solve():
  mod = 10 ** 9 + 7

  def calc(a, b, c):
    ret = binom[a + b + c - 1][b - 1]
    ret += rec2(a - 1, b, c - 1)
    return ret

  @memoize
  def rec2(a, b, c):
    ret = binom[a + b + c][b - 1]
    ret += binom[b + c][b] if a == 0 else rec2(a - 1, b, c)
    ret += binom[a + b][a] if c == 0 else rec2(a, b, c - 1)
    return ret

  N = 333
  binom = [[1]]
  prev = binom[-1]
  for i in range(1, N + 1):
    curr = [1] * (i + 1)
    for j in range(1, i):
      curr[j] = prev[j - 1] + prev[j]
    binom += [curr]
    prev = curr

  T = int(raw_input())
  for _ in range(T):
    a, b, c = map(int, raw_input().split())
    print(calc(a, b, c) % (10 ** 9 + 7))

solve()
0