結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー cielciel
提出日時 2015-12-15 00:26:37
言語 Ruby
(3.3.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 669 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 11,300 KB
実行使用メモリ 15,384 KB
最終ジャッジ日時 2023-09-21 03:23:02
合計ジャッジ時間 8,476 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,148 KB
testcase_01 AC 79 ms
15,164 KB
testcase_02 AC 79 ms
15,120 KB
testcase_03 AC 78 ms
14,956 KB
testcase_04 AC 81 ms
15,060 KB
testcase_05 AC 80 ms
15,152 KB
testcase_06 AC 78 ms
15,252 KB
testcase_07 AC 79 ms
15,232 KB
testcase_08 AC 79 ms
15,156 KB
testcase_09 AC 81 ms
15,236 KB
testcase_10 AC 80 ms
15,112 KB
testcase_11 AC 79 ms
15,064 KB
testcase_12 AC 79 ms
15,060 KB
testcase_13 AC 79 ms
15,192 KB
testcase_14 AC 162 ms
15,372 KB
testcase_15 AC 219 ms
15,192 KB
testcase_16 AC 128 ms
15,284 KB
testcase_17 AC 81 ms
15,152 KB
testcase_18 AC 139 ms
15,344 KB
testcase_19 AC 157 ms
15,380 KB
testcase_20 AC 199 ms
15,168 KB
testcase_21 AC 161 ms
15,384 KB
testcase_22 AC 100 ms
15,272 KB
testcase_23 AC 197 ms
15,240 KB
testcase_24 AC 106 ms
15,324 KB
testcase_25 AC 146 ms
15,192 KB
testcase_26 AC 194 ms
15,280 KB
testcase_27 AC 164 ms
15,360 KB
testcase_28 AC 167 ms
15,364 KB
testcase_29 AC 224 ms
15,228 KB
testcase_30 AC 85 ms
15,236 KB
testcase_31 AC 84 ms
15,204 KB
testcase_32 AC 160 ms
15,356 KB
testcase_33 AC 140 ms
15,380 KB
testcase_34 AC 132 ms
15,272 KB
testcase_35 AC 256 ms
15,200 KB
testcase_36 AC 83 ms
15,172 KB
testcase_37 AC 170 ms
15,380 KB
testcase_38 AC 153 ms
15,244 KB
testcase_39 AC 113 ms
15,352 KB
testcase_40 AC 217 ms
15,288 KB
testcase_41 AC 136 ms
15,276 KB
testcase_42 AC 188 ms
15,268 KB
testcase_43 AC 137 ms
15,308 KB
testcase_44 AC 176 ms
15,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:19: warning: assigned but unused variable - g1
Main.rb:19: warning: assigned but unused variable - g2
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
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
gets
if b==0
	p $<.count{|e|
		x,y=e.split.map(&:to_i)
		x==0&&y==0
	}
else
	g,z1,z2=egcd(a,b)
	a/=g
	b/=g
	g0,g1,g2=egcd(2*a,2*b)
	p $<.count{|e|
		x,y=e.split.map(&:to_i)
		next if x%g!=0 || y%g!=0
		x/=g
		y/=g
		z=b*b-a*a
		w=z2*x*a+z1*x*b-y
		if -w%z.gcd(g0)==0
=begin
			_,k1,k2=egcd(z,g0)
			e=0
			f=0
			n=w*k1%g0+g0*e
			m=(z*n+w)/g0
			_d=g1*m+2*b*f
			_b=g2*m-2*a*f
			_a=z1*x+b*n-_b
			_c=z2*x-a*n-_d
			raise if (_a+_b)*a+(_c+_d)*b!=x
			raise if (_c-_d)*a+(_a-_b)*b!=y
			p [_a,_b,_c,_d]
=end
			true
		else
			false
		end
	}
end
0