結果

問題 No.173 カードゲーム(Medium)
ユーザー cielciel
提出日時 2020-06-12 23:00:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,538 ms / 3,000 ms
コード長 556 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 15,544 KB
最終ジャッジ日時 2023-09-06 11:09:12
合計ジャッジ時間 17,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
15,412 KB
testcase_01 AC 292 ms
15,168 KB
testcase_02 AC 2,140 ms
15,356 KB
testcase_03 AC 2,144 ms
15,544 KB
testcase_04 AC 2,116 ms
15,440 KB
testcase_05 AC 1,867 ms
15,360 KB
testcase_06 AC 1,595 ms
15,208 KB
testcase_07 AC 1,507 ms
15,428 KB
testcase_08 AC 1,510 ms
15,404 KB
testcase_09 AC 2,538 ms
15,464 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
n,pa,pb=gets.split.zip([:to_i.to_proc,:to_f.to_proc,:to_f.to_proc]).map{|x,y|y.call(x)}
A=gets.split.map(&:to_i).sort
B=gets.split.map(&:to_i).sort
win=0
total=0
50000.times{
	total+=1
	a=A.dup
	b=B.dup
	a_score=b_score=0
	n.times{|i|
		a_idx=i==n-1||rand<pa ? 0 : [*1...n-i].sample
		b_idx=i==n-1||rand<pb ? 0 : [*1...n-i].sample
		score=a[a_idx]+b[b_idx]
		a_score+=score if a[a_idx]>b[b_idx]
		b_score+=score if a[a_idx]<b[b_idx]
		a=a[0,a_idx]+a[a_idx+1..-1]
		b=b[0,b_idx]+b[b_idx+1..-1]
	}
	win+=1 if a_score>b_score
}
p win*1.0/total
0