結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー | yuruhiya |
提出日時 | 2020-10-19 19:24:39 |
言語 | Crystal (1.11.2) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 2,206 bytes |
コンパイル時間 | 11,747 ms |
コンパイル使用メモリ | 295,032 KB |
実行使用メモリ | 93,604 KB |
最終ジャッジ日時 | 2024-06-30 21:25:57 |
合計ジャッジ時間 | 29,567 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 139 ms
73,216 KB |
testcase_01 | AC | 140 ms
73,252 KB |
testcase_02 | AC | 140 ms
73,280 KB |
testcase_03 | AC | 142 ms
73,260 KB |
testcase_04 | AC | 141 ms
73,220 KB |
testcase_05 | AC | 141 ms
73,284 KB |
testcase_06 | AC | 144 ms
73,264 KB |
testcase_07 | AC | 141 ms
73,188 KB |
testcase_08 | AC | 152 ms
73,228 KB |
testcase_09 | AC | 157 ms
74,532 KB |
testcase_10 | AC | 146 ms
74,460 KB |
testcase_11 | AC | 143 ms
75,876 KB |
testcase_12 | AC | 149 ms
74,164 KB |
testcase_13 | AC | 148 ms
81,256 KB |
testcase_14 | AC | 147 ms
76,324 KB |
testcase_15 | AC | 149 ms
74,020 KB |
testcase_16 | AC | 146 ms
74,120 KB |
testcase_17 | AC | 140 ms
76,340 KB |
testcase_18 | AC | 163 ms
89,352 KB |
testcase_19 | AC | 142 ms
73,320 KB |
testcase_20 | AC | 135 ms
73,252 KB |
testcase_21 | AC | 142 ms
73,208 KB |
testcase_22 | AC | 142 ms
73,236 KB |
testcase_23 | AC | 145 ms
73,196 KB |
testcase_24 | AC | 142 ms
73,256 KB |
testcase_25 | AC | 141 ms
73,288 KB |
testcase_26 | AC | 147 ms
73,208 KB |
testcase_27 | AC | 143 ms
73,272 KB |
testcase_28 | AC | 141 ms
73,200 KB |
testcase_29 | AC | 128 ms
73,304 KB |
testcase_30 | AC | 139 ms
73,220 KB |
testcase_31 | AC | 143 ms
73,212 KB |
testcase_32 | AC | 142 ms
73,316 KB |
testcase_33 | AC | 145 ms
73,196 KB |
testcase_34 | AC | 142 ms
73,244 KB |
testcase_35 | AC | 139 ms
73,256 KB |
testcase_36 | AC | 148 ms
73,224 KB |
testcase_37 | AC | 141 ms
73,216 KB |
testcase_38 | AC | 145 ms
73,260 KB |
testcase_39 | AC | 143 ms
73,252 KB |
testcase_40 | AC | 146 ms
73,256 KB |
testcase_41 | AC | 143 ms
73,196 KB |
testcase_42 | AC | 151 ms
73,304 KB |
testcase_43 | AC | 133 ms
73,192 KB |
testcase_44 | AC | 143 ms
73,212 KB |
testcase_45 | AC | 148 ms
73,232 KB |
testcase_46 | AC | 150 ms
73,216 KB |
testcase_47 | AC | 148 ms
73,200 KB |
testcase_48 | AC | 155 ms
73,196 KB |
testcase_49 | AC | 168 ms
87,692 KB |
testcase_50 | AC | 143 ms
73,832 KB |
testcase_51 | AC | 153 ms
74,092 KB |
testcase_52 | AC | 150 ms
75,888 KB |
testcase_53 | AC | 154 ms
74,384 KB |
testcase_54 | AC | 148 ms
77,896 KB |
testcase_55 | AC | 134 ms
73,384 KB |
testcase_56 | AC | 147 ms
74,220 KB |
testcase_57 | AC | 160 ms
78,776 KB |
testcase_58 | AC | 161 ms
84,804 KB |
testcase_59 | AC | 160 ms
81,800 KB |
testcase_60 | AC | 154 ms
77,184 KB |
testcase_61 | AC | 168 ms
93,604 KB |
testcase_62 | AC | 158 ms
77,200 KB |
testcase_63 | AC | 161 ms
86,580 KB |
testcase_64 | AC | 145 ms
76,664 KB |
testcase_65 | AC | 150 ms
74,900 KB |
testcase_66 | AC | 165 ms
77,312 KB |
testcase_67 | AC | 148 ms
76,596 KB |
testcase_68 | AC | 157 ms
76,340 KB |
testcase_69 | AC | 150 ms
73,360 KB |
testcase_70 | AC | 145 ms
73,212 KB |
testcase_71 | AC | 142 ms
73,192 KB |
testcase_72 | AC | 154 ms
73,192 KB |
testcase_73 | AC | 135 ms
73,260 KB |
testcase_74 | AC | 148 ms
73,240 KB |
testcase_75 | AC | 143 ms
73,232 KB |
testcase_76 | AC | 144 ms
73,288 KB |
testcase_77 | AC | 145 ms
73,316 KB |
testcase_78 | AC | 150 ms
73,376 KB |
testcase_79 | AC | 149 ms
73,204 KB |
testcase_80 | AC | 147 ms
73,288 KB |
testcase_81 | AC | 154 ms
73,288 KB |
testcase_82 | AC | 148 ms
73,224 KB |
testcase_83 | AC | 139 ms
73,176 KB |
testcase_84 | AC | 148 ms
73,380 KB |
testcase_85 | AC | 145 ms
73,280 KB |
testcase_86 | AC | 154 ms
73,280 KB |
testcase_87 | AC | 149 ms
73,240 KB |
testcase_88 | AC | 151 ms
73,304 KB |
testcase_89 | AC | 147 ms
78,088 KB |
testcase_90 | AC | 155 ms
80,028 KB |
testcase_91 | AC | 167 ms
88,908 KB |
testcase_92 | AC | 160 ms
76,048 KB |
testcase_93 | AC | 164 ms
81,692 KB |
testcase_94 | AC | 141 ms
73,436 KB |
testcase_95 | AC | 150 ms
81,816 KB |
testcase_96 | AC | 156 ms
79,692 KB |
testcase_97 | AC | 147 ms
79,168 KB |
testcase_98 | AC | 153 ms
76,800 KB |
ソースコード
lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end struct ModInt @@MOD = 1_000_000_007i64 def self.mod @@MOD end def self.zero ModInt.new(0) end def initialize(n) @n = n.to_i64 % @@MOD end getter n : Int64 def + : self self end def - : self ModInt.new(n != 0 ? @@MOD - @n : 0) end def +(m) ModInt.new(@n + m.to_i64 % @@MOD) end def -(m) ModInt.new(@n - m.to_i64 % @@MOD) end def *(m) ModInt.new(@n * m.to_i64 % @@MOD) end def /(m) raise DivisionByZeroError.new if m == 0 a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64 while b != 0 t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u end ModInt.new(@n * u) end def //(m) self / m end def **(m : Int) t, res = self, ModInt.new(1) while m > 0 res *= t if m.odd? t *= t m >>= 1 end res end def ==(m) @n == m.to_i64 end def !=(m) @n != m.to_i64 end def succ self + 1 end def pred self - 1 end def to_i64 : Int64 @n end delegate to_s, to: @n delegate inspect, to: @n end struct Int def to_mint : ModInt ModInt.new(self) end end class Comb(T) def initialize(@Max = 3000009) @fac = Array(T).new(@Max, T.zero) @finv = Array(T).new(@Max, T.zero) @inv = Array(T).new(@Max, T.zero) @fac[0] = @fac[1] = T.new(1) @finv[0] = @finv[1] = T.new(1) @inv[1] = T.new(1) (2...@Max).each do |i| @fac[i] = @fac[i - 1] * i @inv[i] = -@inv[T.mod % i] * (T.mod / i) @finv[i] = @finv[i - 1] * @inv[i] end end def p(n, r) (n < r || n < 0 || r < 0) ? T.zero : @fac[n] * @finv[n - r] end def c(n, r) (n < r || n < 0 || r < 0) ? T.zero : @fac[n] * @finv[r] * @finv[n - r] end def h(n, r) (n < 0 || r < 0) ? T.zero : r == 0 ? T.new(1) : c(n + r - 1, r) end def fact(n) @fac[n] end end comb = Comb(ModInt).new n = read_line.to_i a = read_line.split.map(&.to_i) if a.sum == 0 puts 1 elsif (ans = comb.h(n - a.sum - a.size + 2, a.size)) != 0 puts ans else puts "NA" end