結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー LeonardoneLeonardone
提出日時 2015-12-15 02:30:11
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 806 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-09-15 12:58:46
合計ジャッジ時間 8,732 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gs(); gets.chomp; end
def gi(); gets.to_i; end
def gss(); gets.chomp.split; end
def gis(); gss.map(&:to_i); end

# 解説読後
# http://yukicoder.me/problems/849/editorial

P, Q = gis
N = gi

g = P * Q == 0 ? 1 : P.gcd(Q)
pg = P / g
qg = Q / g

c = 0

N.times do
    x, y = gis.map(&:abs)
    
    if x == 0 && y == 0
        c += 1
        next
    end
    if P == 0
        c += 1 if x % Q == 0 && y % Q == 0
        next
    end
    if Q == 0
        c += 1 if x % P == 0 && y % P == 0
        next
    end
    
    next if x % g > 0 || y % g > 0
    
    x /= g
    y /= g
    
    u, v = [x % 2, y % 2].minmax
    
    if u == 0 && v == 1
        c += 1 if pg % 2 == 0 || qg % 2 == 0
    else
        c += 1
    end
    
end

p c
0