結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー char134217728char134217728
提出日時 2017-09-05 20:32:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 471 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 40,192 KB
最終ジャッジ日時 2024-04-24 14:08:11
合計ジャッジ時間 14,375 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
12,288 KB
testcase_01 AC 90 ms
12,160 KB
testcase_02 AC 89 ms
12,288 KB
testcase_03 AC 89 ms
12,160 KB
testcase_04 AC 171 ms
12,160 KB
testcase_05 AC 92 ms
12,032 KB
testcase_06 AC 91 ms
12,288 KB
testcase_07 AC 88 ms
12,288 KB
testcase_08 AC 89 ms
12,160 KB
testcase_09 AC 188 ms
13,952 KB
testcase_10 AC 113 ms
13,440 KB
testcase_11 AC 196 ms
15,232 KB
testcase_12 AC 104 ms
13,440 KB
testcase_13 AC 169 ms
22,144 KB
testcase_14 AC 116 ms
15,360 KB
testcase_15 AC 110 ms
12,800 KB
testcase_16 AC 135 ms
13,312 KB
testcase_17 AC 165 ms
14,720 KB
testcase_18 AC 254 ms
32,000 KB
testcase_19 AC 89 ms
12,160 KB
testcase_20 AC 90 ms
12,160 KB
testcase_21 AC 89 ms
12,288 KB
testcase_22 AC 92 ms
12,160 KB
testcase_23 AC 91 ms
12,160 KB
testcase_24 AC 92 ms
12,160 KB
testcase_25 AC 90 ms
12,160 KB
testcase_26 AC 90 ms
12,160 KB
testcase_27 AC 93 ms
12,160 KB
testcase_28 AC 89 ms
12,288 KB
testcase_29 AC 90 ms
12,160 KB
testcase_30 AC 91 ms
12,288 KB
testcase_31 AC 89 ms
12,288 KB
testcase_32 AC 90 ms
12,160 KB
testcase_33 AC 90 ms
12,160 KB
testcase_34 AC 92 ms
12,160 KB
testcase_35 AC 91 ms
12,288 KB
testcase_36 AC 91 ms
12,288 KB
testcase_37 AC 92 ms
12,288 KB
testcase_38 AC 91 ms
12,160 KB
testcase_39 AC 91 ms
12,288 KB
testcase_40 AC 91 ms
12,288 KB
testcase_41 AC 90 ms
12,288 KB
testcase_42 AC 90 ms
12,160 KB
testcase_43 AC 90 ms
12,288 KB
testcase_44 AC 88 ms
12,288 KB
testcase_45 AC 89 ms
12,160 KB
testcase_46 AC 91 ms
12,032 KB
testcase_47 AC 91 ms
12,288 KB
testcase_48 AC 88 ms
12,288 KB
testcase_49 AC 220 ms
33,280 KB
testcase_50 AC 99 ms
12,928 KB
testcase_51 AC 98 ms
12,672 KB
testcase_52 AC 107 ms
15,232 KB
testcase_53 AC 99 ms
13,440 KB
testcase_54 AC 117 ms
16,640 KB
testcase_55 AC 94 ms
12,288 KB
testcase_56 AC 100 ms
13,056 KB
testcase_57 AC 141 ms
20,608 KB
testcase_58 AC 182 ms
29,824 KB
testcase_59 AC 163 ms
25,984 KB
testcase_60 AC 125 ms
18,304 KB
testcase_61 AC 250 ms
40,192 KB
testcase_62 AC 126 ms
18,304 KB
testcase_63 AC 185 ms
30,208 KB
testcase_64 AC 119 ms
16,384 KB
testcase_65 AC 109 ms
14,336 KB
testcase_66 AC 125 ms
17,536 KB
testcase_67 AC 122 ms
17,024 KB
testcase_68 AC 119 ms
16,640 KB
testcase_69 AC 137 ms
12,160 KB
testcase_70 AC 113 ms
12,160 KB
testcase_71 AC 124 ms
12,160 KB
testcase_72 AC 104 ms
12,160 KB
testcase_73 AC 113 ms
12,160 KB
testcase_74 AC 124 ms
12,160 KB
testcase_75 AC 122 ms
12,160 KB
testcase_76 AC 101 ms
12,032 KB
testcase_77 AC 149 ms
12,160 KB
testcase_78 AC 95 ms
12,160 KB
testcase_79 AC 90 ms
12,160 KB
testcase_80 AC 90 ms
12,160 KB
testcase_81 AC 91 ms
12,160 KB
testcase_82 AC 91 ms
12,160 KB
testcase_83 AC 90 ms
12,160 KB
testcase_84 AC 90 ms
12,160 KB
testcase_85 AC 91 ms
12,160 KB
testcase_86 AC 90 ms
12,032 KB
testcase_87 AC 91 ms
12,032 KB
testcase_88 AC 90 ms
12,160 KB
testcase_89 AC 146 ms
18,944 KB
testcase_90 AC 182 ms
23,040 KB
testcase_91 AC 259 ms
32,512 KB
testcase_92 AC 112 ms
14,720 KB
testcase_93 AC 188 ms
25,600 KB
testcase_94 AC 94 ms
12,288 KB
testcase_95 AC 191 ms
26,240 KB
testcase_96 AC 162 ms
21,888 KB
testcase_97 AC 160 ms
21,504 KB
testcase_98 AC 129 ms
16,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

mod = 1000000007
n = gets.to_i
a = gets.split(" ").map &:to_i
if a[0] == 0
  p 1
  exit
end
n = n - a.sum + 1
m = a.length
if(n < m)
  puts "NA"
  exit
end
f = 1
def pm(a, b, c)
  ret = 1
  while b > 0
    ret = ret * a % c if b & 1 > 0
    a = a * a % c;
    b /= 2
  end
  ret
end
fn = fm = fnm = 1;
(1..n).each do |i|
  f = f * i % mod
  fn = f if i == n
  fm = pm(f, mod - 2, mod) if i == m
  fnm = pm(f, mod - 2, mod) if i == n - m
end
puts fnm * fn % mod * fm % mod
0