結果

問題 No.797 Noelちゃんとピラミッド
ユーザー ikdikd
提出日時 2019-03-15 23:19:40
言語 Nim
(2.0.2)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 2,923 ms
コンパイル使用メモリ 69,268 KB
実行使用メモリ 15,564 KB
最終ジャッジ日時 2023-09-14 14:18:22
合計ジャッジ時間 10,706 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 176 ms
15,424 KB
testcase_04 AC 176 ms
15,564 KB
testcase_05 AC 173 ms
13,060 KB
testcase_06 AC 174 ms
12,892 KB
testcase_07 AC 174 ms
12,848 KB
testcase_08 AC 174 ms
13,036 KB
testcase_09 AC 173 ms
13,100 KB
testcase_10 AC 174 ms
12,944 KB
testcase_11 AC 170 ms
13,076 KB
testcase_12 AC 170 ms
13,080 KB
testcase_13 AC 171 ms
12,892 KB
testcase_14 AC 171 ms
12,924 KB
testcase_15 AC 175 ms
13,084 KB
testcase_16 AC 171 ms
12,892 KB
testcase_17 AC 174 ms
12,956 KB
testcase_18 AC 174 ms
13,096 KB
testcase_19 AC 173 ms
12,936 KB
testcase_20 AC 173 ms
12,892 KB
testcase_21 AC 174 ms
12,912 KB
testcase_22 AC 173 ms
12,844 KB
testcase_23 AC 124 ms
10,140 KB
testcase_24 AC 40 ms
4,972 KB
testcase_25 AC 106 ms
8,936 KB
testcase_26 AC 99 ms
8,552 KB
testcase_27 AC 165 ms
11,944 KB
testcase_28 AC 153 ms
11,108 KB
testcase_29 AC 23 ms
4,376 KB
testcase_30 AC 36 ms
4,952 KB
testcase_31 AC 123 ms
9,992 KB
testcase_32 AC 53 ms
5,512 KB
testcase_33 AC 102 ms
9,024 KB
testcase_34 AC 71 ms
6,756 KB
testcase_35 AC 167 ms
12,936 KB
testcase_36 AC 19 ms
4,380 KB
testcase_37 AC 150 ms
11,108 KB
testcase_38 AC 161 ms
11,504 KB
testcase_39 AC 101 ms
9,000 KB
testcase_40 AC 19 ms
4,376 KB
testcase_41 AC 28 ms
4,464 KB
testcase_42 AC 94 ms
7,732 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 2 ms
4,376 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

proc modpow(a, x, mo: int64): int64 =
  if x == 0:
    return 1
  elif x == 1:
    return a
  elif x mod 2 == 0:
    return modpow(a * a mod mo, x div 2, mo)
  else:
    return a * modpow(a, x - 1, mo) mod mo

proc cmb(n, k: int, fact: seq[int64], mo: int64): int64 =
  if n < k:
    return 0
  elif k == 0:
    return 1
  elif n == k:
    return 1
  else:
    result = fact[n]
    result = result * modpow(fact[k], mo - 2, mo) mod mo
    result = result * modpow(fact[n - k], mo - 2, mo) mod mo
    return result

proc main() =
  let
    n = stdin.readLine.strip.parseInt
    a = stdin.readLine.strip.split.map(parseInt)
    mo = 1000000000 + 7
  var fact = newSeq[int64](n + 1)
  fact[0] = 1
  for i in 1..n:
    fact[i] = fact[i - 1] * i mod mo
  var ans: int64 = 0
  for k, it in a:
    ans = (ans + cmb(n - 1, k, fact, mo) * it) mod mo
  echo ans
main()
0