結果

問題 No.1650 Moving Coins
ユーザー 小野寺健小野寺健
提出日時 2021-11-01 13:10:00
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 617 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 62,728 KB
最終ジャッジ日時 2024-04-18 08:10:38
合計ジャッジ時間 22,172 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
12,160 KB
testcase_01 AC 92 ms
19,840 KB
testcase_02 AC 79 ms
12,160 KB
testcase_03 WA -
testcase_04 AC 282 ms
33,280 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 566 ms
57,696 KB
testcase_23 AC 561 ms
57,692 KB
testcase_24 AC 350 ms
43,136 KB
testcase_25 AC 371 ms
36,096 KB
testcase_26 AC 238 ms
45,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split(" ").map{|s| s.to_i}
B = gets.split(" ").map{|s| s.to_i}

q = []
c = Array.new((A+B).max, false)
0.upto(N-1) {|i|
	a, b = A[i], B[i]
	c[a-1] = true
	q << [i+1, a-1, b-a] if a != b
}

ans = []
top = true
while q.length > 0 do
	i, pos, diff = q[top ? 0 : -1]
	d = diff > 0 ? 1 : -1
	if c[pos+d] then
		top = !top
		i, pos, diff = q[top ? 0 : -1]
		d = diff > 0 ? 1 : -1		
	end
	ans << [i, d > 0 ? "R" : "L"]
	diff -= d
	if diff == 0 then
		if top then
			q.shift
		else
			q.pop
		end
	else
		q[top ? 0 : -1] = [i, pos+d, diff]
	end
end

puts ans.length
ans.each {|i, d|
	puts "#{i} #{d}"
}
0