結果

問題 No.1650 Moving Coins
ユーザー 小野寺健小野寺健
提出日時 2021-11-01 12:39:35
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 515 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 56,192 KB
最終ジャッジ日時 2024-04-18 07:29:08
合計ジャッジ時間 16,989 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
17,536 KB
testcase_01 AC 94 ms
19,968 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 437 ms
39,424 KB
testcase_04 AC 330 ms
33,024 KB
testcase_05 AC 411 ms
40,832 KB
testcase_06 AC 448 ms
41,984 KB
testcase_07 AC 457 ms
43,520 KB
testcase_08 AC 511 ms
55,040 KB
testcase_09 AC 1,211 ms
52,224 KB
testcase_10 AC 495 ms
56,192 KB
testcase_11 AC 573 ms
52,736 KB
testcase_12 AC 580 ms
45,440 KB
testcase_13 AC 610 ms
43,904 KB
testcase_14 AC 612 ms
50,176 KB
testcase_15 AC 499 ms
38,600 KB
testcase_16 AC 565 ms
50,688 KB
testcase_17 AC 536 ms
51,712 KB
testcase_18 AC 600 ms
51,320 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = []

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

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