結果
問題 | No.187 中華風 (Hard) |
ユーザー | tubo28 |
提出日時 | 2015-04-20 01:17:37 |
言語 | Ruby (3.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 728 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 11,428 KB |
実行使用メモリ | 23,428 KB |
最終ジャッジ日時 | 2023-09-17 22:29:34 |
合計ジャッジ時間 | 3,979 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 91 ms
15,296 KB |
testcase_01 | AC | 83 ms
15,020 KB |
testcase_02 | AC | 116 ms
20,680 KB |
testcase_03 | AC | 115 ms
20,452 KB |
testcase_04 | AC | 138 ms
23,148 KB |
testcase_05 | AC | 132 ms
23,080 KB |
testcase_06 | AC | 135 ms
23,344 KB |
testcase_07 | AC | 135 ms
23,428 KB |
testcase_08 | AC | 138 ms
23,192 KB |
testcase_09 | AC | 138 ms
23,264 KB |
testcase_10 | AC | 135 ms
23,328 KB |
testcase_11 | AC | 133 ms
22,964 KB |
testcase_12 | AC | 133 ms
22,936 KB |
testcase_13 | AC | 84 ms
15,360 KB |
testcase_14 | AC | 85 ms
15,388 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 83 ms
15,240 KB |
testcase_18 | AC | 86 ms
15,196 KB |
testcase_19 | AC | 82 ms
15,092 KB |
testcase_20 | AC | 125 ms
22,308 KB |
testcase_21 | AC | 83 ms
15,104 KB |
testcase_22 | AC | 135 ms
23,268 KB |
testcase_23 | AC | 83 ms
15,212 KB |
testcase_24 | AC | 83 ms
15,104 KB |
コンパイルメッセージ
Syntax OK
ソースコード
def extgcd(a, b) if b.zero? {x: 1, y: 0, gcd: a} else prev = extgcd(b, a % b) { x: prev[:y], y: prev[:x] - (a / b) * prev[:y], gcd: prev[:gcd] } end end def mod_inv(a,m) res = extgcd(a,m) x = res[:x] (m + x%m) % m end def lc(as,bs,ms) x,m = 0,1 as.size.times do |i| a = as[i]*m b = bs[i] - as[i]*x d = ms[i].gcd(a) return if b%d != 0 t = b/d * mod_inv(a/d, ms[i]/d) % (ms[i]/d) x = x + m*t m *= ms[i]/d end return [x%m, m] end n = gets.to_i t = [] n.times do x,y = gets.chomp.split.map(&:to_i) t << [x,y] end xs,ys = t.transpose as = [1] * n ans = lc(as,xs,ys) puts -> (x){ if x.nil? -1 else x[0] == 0 ? x[1] : x[0] % 1000000007 end }.call(ans)