結果

問題 No.849 yuki国の分割統治
ユーザー betrue12betrue12
提出日時 2019-07-05 22:30:07
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 554 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-04-16 07:47:17
合計ジャッジ時間 8,720 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
12,160 KB
testcase_01 AC 90 ms
12,160 KB
testcase_02 AC 90 ms
12,160 KB
testcase_03 AC 90 ms
12,288 KB
testcase_04 AC 90 ms
12,032 KB
testcase_05 AC 89 ms
12,288 KB
testcase_06 AC 88 ms
12,032 KB
testcase_07 RE -
testcase_08 AC 319 ms
16,768 KB
testcase_09 AC 322 ms
14,976 KB
testcase_10 AC 327 ms
13,184 KB
testcase_11 AC 296 ms
14,848 KB
testcase_12 AC 307 ms
12,800 KB
testcase_13 AC 325 ms
14,720 KB
testcase_14 AC 330 ms
14,080 KB
testcase_15 AC 302 ms
16,640 KB
testcase_16 AC 363 ms
19,072 KB
testcase_17 AC 311 ms
12,416 KB
testcase_18 AC 357 ms
21,632 KB
testcase_19 AC 333 ms
13,440 KB
testcase_20 AC 360 ms
17,280 KB
testcase_21 AC 305 ms
12,288 KB
testcase_22 AC 368 ms
18,816 KB
testcase_23 AC 361 ms
17,152 KB
testcase_24 AC 326 ms
13,184 KB
testcase_25 AC 366 ms
22,400 KB
testcase_26 AC 90 ms
12,160 KB
testcase_27 AC 88 ms
12,032 KB
testcase_28 AC 88 ms
12,160 KB
testcase_29 AC 89 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def extgcd(a, b)
    if b == 0
        {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

a, b, c, d = gets.split.map(&:to_i)
gx = a.gcd(c);
dy0 = (c*b-a*d).abs / gx

hash = extgcd(a/gx, c/gx)
dy1 = hash[:x]*b + hash[:y]*d

result = {}
N = gets.to_i
N.times do
    x, y = gets.split.map(&:to_i)
    x2 = x % gx
    y2 = y - (x-x2)/gx*dy1
    y2 %= dy0 if dy0 > 0
    result[[x2, y2]] = true
end
puts result.size
0