結果
問題 |
No.1650 Moving Coins
|
ユーザー |
|
提出日時 | 2021-11-01 13:10:00 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 617 bytes |
コンパイル時間 | 134 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 62,824 KB |
最終ジャッジ日時 | 2024-10-10 01:21:38 |
合計ジャッジ時間 | 25,006 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 WA * 18 |
コンパイルメッセージ
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 = [] 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}" }