結果

問題 No.1650 Moving Coins
コンテスト
ユーザー siman
提出日時 2021-08-21 02:43:24
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
RE  
実行時間 -
コード長 789 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 56 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 89,068 KB
最終ジャッジ日時 2026-05-01 20:38:59
合計ジャッジ時間 15,035 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 RE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

positions = Array.new(1_000_010, false)

A.each do |a|
  positions[a] = true
end

def dfs(i, positions, commands)
  while A[i] != B[i]
    a = A[i]

    if A[i] < B[i]
      if positions[a + 1]
        dfs(i + 1, positions, commands)
      else
        commands << [i, 'R']
        positions[a] = false
        positions[a + 1] = true
        A[i] += 1
      end
    else
      if positions[a - 1]
        dfs(i + 1, positions, commands)
      else
        commands << [i, 'L']
        positions[a] = false
        positions[a - 1] = true
        A[i] -= 1
      end
    end
  end
end

commands = []

N.times do |i|
  dfs(i, positions, commands)
end

puts commands.size
puts commands.map { |i, d| [i + 1, d].join(' ') }
0