結果
| 問題 |
No.1650 Moving Coins
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-01 12:51:39 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 571 bytes |
| コンパイル時間 | 328 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 57,984 KB |
| 最終ジャッジ日時 | 2024-10-10 01:05:08 |
| 合計ジャッジ時間 | 16,423 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 TLE * 1 -- * 7 |
コンパイルメッセージ
Syntax OK
ソースコード
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
while diff != 0 and (not c[pos+d]) do
diff -= d
pos += d
ans << [i, d > 0 ? "R" : "L"]
end
c[pos] = true
q << [i, pos, diff] if diff != 0
end
end
puts ans.length
ans.each {|i, d|
puts "#{i} #{d}"
}