結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー cielciel
提出日時 2015-12-14 04:17:49
言語 Ruby
(3.3.0)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 11,444 KB
実行使用メモリ 15,496 KB
最終ジャッジ日時 2023-09-21 03:15:55
合計ジャッジ時間 8,661 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,320 KB
testcase_01 AC 78 ms
15,280 KB
testcase_02 AC 79 ms
15,244 KB
testcase_03 AC 79 ms
15,104 KB
testcase_04 AC 79 ms
15,196 KB
testcase_05 AC 80 ms
15,152 KB
testcase_06 AC 79 ms
15,100 KB
testcase_07 AC 78 ms
15,196 KB
testcase_08 AC 78 ms
15,152 KB
testcase_09 AC 79 ms
15,268 KB
testcase_10 AC 79 ms
15,000 KB
testcase_11 AC 80 ms
15,060 KB
testcase_12 AC 79 ms
15,372 KB
testcase_13 AC 79 ms
15,148 KB
testcase_14 AC 179 ms
15,436 KB
testcase_15 AC 199 ms
15,116 KB
testcase_16 AC 124 ms
15,432 KB
testcase_17 AC 80 ms
15,196 KB
testcase_18 AC 149 ms
15,296 KB
testcase_19 AC 171 ms
15,496 KB
testcase_20 AC 222 ms
15,232 KB
testcase_21 AC 179 ms
15,352 KB
testcase_22 AC 99 ms
15,360 KB
testcase_23 AC 222 ms
15,432 KB
testcase_24 AC 112 ms
15,388 KB
testcase_25 AC 157 ms
15,132 KB
testcase_26 AC 215 ms
15,296 KB
testcase_27 AC 181 ms
15,440 KB
testcase_28 AC 182 ms
15,380 KB
testcase_29 AC 254 ms
15,000 KB
testcase_30 AC 82 ms
15,344 KB
testcase_31 AC 81 ms
15,240 KB
testcase_32 AC 166 ms
15,328 KB
testcase_33 AC 152 ms
15,448 KB
testcase_34 AC 140 ms
15,288 KB
testcase_35 AC 288 ms
15,332 KB
testcase_36 AC 84 ms
15,360 KB
testcase_37 AC 183 ms
15,276 KB
testcase_38 AC 163 ms
15,452 KB
testcase_39 AC 117 ms
15,196 KB
testcase_40 AC 241 ms
15,188 KB
testcase_41 AC 143 ms
15,124 KB
testcase_42 AC 204 ms
15,192 KB
testcase_43 AC 146 ms
15,228 KB
testcase_44 AC 193 ms
15,216 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
#coding:utf-8
def egcd(x,y)
	return [x,1,0] if y==0
	g,a,b=egcd(y,x%y)
	[g,b,a-x/y*b]
end

a,b=gets.split.map(&:to_i).sort
if b==0
	gets;p $<.count{|e|
		x,y=e.split.map(&:to_i)
		x==0&&y==0
	}
elsif a==0
	gets;p $<.count{|e|
		x,y=e.split.map(&:to_i)
		x%b==0&&y%b==0
	}
else
	g=a.gcd b
	a/=g
	b/=g
	z=egcd(a,b)
	gets;p $<.count{|e|
		x,y=e.split.map{|e|e.to_i.abs}.sort
		next if x%g!=0 || y%g!=0
		x/=g
		y/=g

		#p z
		#p z[1]*x*b
		#((QQ-PP)n+z2XP+z1XQ-Y)%gcd(2P,2Q)==0
		g0=(2*a).gcd(2*b)
		_z=b*b-a*a
		w=z[2]*x*a+z[1]*x*b-y
		#zn+w%g0==0
		#zn%g0==-w%g0
		#p [-w,_z,g0]
		-w%_z.gcd(g0)==0


=begin
		α=z[1]*x
		β=z[2]*x
		#p α
		#p β
		p a*β+b*α-y
		#(β-2d)A + (α-2b)B == y
		#2Ad + 2Bb == Aβ+Bα-y
		w=egcd(2*a,2*b)
		p w[0]
		next if p (a*β+b*α-y)%w[0]!=0
		true
		#o=w[1]*(a*β+b*α-y);q=w[2]*(a*β+b*α-y)
		#β-2*o>=0 && α-2*q
=end
	}
end
0