結果

問題 No.110 しましまピラミッド
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-16 09:17:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 571 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 11,340 KB
実行使用メモリ 15,332 KB
最終ジャッジ日時 2023-08-30 04:02:30
合計ジャッジ時間 3,823 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,116 KB
testcase_01 AC 81 ms
15,276 KB
testcase_02 AC 80 ms
15,060 KB
testcase_03 AC 79 ms
15,160 KB
testcase_04 AC 79 ms
15,280 KB
testcase_05 AC 81 ms
15,048 KB
testcase_06 AC 79 ms
15,272 KB
testcase_07 AC 79 ms
15,164 KB
testcase_08 AC 80 ms
15,140 KB
testcase_09 AC 81 ms
15,284 KB
testcase_10 AC 79 ms
15,108 KB
testcase_11 AC 80 ms
15,132 KB
testcase_12 AC 81 ms
15,316 KB
testcase_13 AC 81 ms
15,104 KB
testcase_14 AC 80 ms
15,332 KB
testcase_15 AC 80 ms
15,112 KB
testcase_16 AC 81 ms
15,312 KB
testcase_17 AC 80 ms
15,088 KB
testcase_18 AC 78 ms
15,096 KB
testcase_19 AC 80 ms
15,128 KB
testcase_20 AC 81 ms
15,024 KB
testcase_21 AC 81 ms
15,128 KB
testcase_22 AC 80 ms
15,108 KB
testcase_23 AC 80 ms
15,316 KB
testcase_24 AC 80 ms
15,188 KB
testcase_25 AC 81 ms
15,188 KB
testcase_26 AC 81 ms
15,108 KB
testcase_27 AC 80 ms
15,104 KB
testcase_28 AC 78 ms
15,244 KB
testcase_29 AC 80 ms
15,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(h,c,b,w,ans)
	if b.empty? ==true && c.empty? ==true
		return ans
	end
	if (c=="w" && b.empty? ==true) || (c=="b" && w.empty? ==true)
		return ans
	end
	res=0
	if c=="w"
		e=b.pop
		if e<h
			res=f(e,"b",b,w,ans+1)
		else
			res= f(h,"w",b,w,ans)
		end
		b.push(e)
	else
		e=w.pop
		if e<h
			res= f(e,"w",b,w,ans+1)
		else
			res= f(h,"b",b,w,ans)
		end
		w.push(e)
	end
	return res
end

gets
b=gets.split.map{|e| e.to_i}.sort
gets
w=gets.split.map{|e| e.to_i}.sort

e=b.pop
ans0=f(e,"b",b,w,1)
b.push(e)

e=w.pop
ans1=f(e,"w",b,w,1)
w.push(e)

puts [ans0,ans1].max
0