結果

問題 No.1650 Moving Coins
ユーザー simansiman
提出日時 2021-08-21 02:43:24
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 789 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 73,600 KB
最終ジャッジ日時 2024-04-22 12:00:25
合計ジャッジ時間 18,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
20,096 KB
testcase_01 AC 96 ms
20,224 KB
testcase_02 AC 96 ms
20,224 KB
testcase_03 AC 544 ms
65,536 KB
testcase_04 AC 418 ms
53,632 KB
testcase_05 AC 522 ms
61,568 KB
testcase_06 AC 556 ms
66,560 KB
testcase_07 AC 556 ms
67,200 KB
testcase_08 AC 633 ms
69,120 KB
testcase_09 AC 656 ms
70,784 KB
testcase_10 AC 650 ms
70,528 KB
testcase_11 AC 662 ms
71,296 KB
testcase_12 AC 609 ms
68,608 KB
testcase_13 AC 608 ms
68,480 KB
testcase_14 AC 648 ms
70,784 KB
testcase_15 AC 592 ms
67,820 KB
testcase_16 AC 665 ms
71,296 KB
testcase_17 AC 652 ms
68,736 KB
testcase_18 AC 682 ms
72,832 KB
testcase_19 RE -
testcase_20 AC 711 ms
73,472 KB
testcase_21 RE -
testcase_22 AC 733 ms
73,600 KB
testcase_23 AC 727 ms
73,472 KB
testcase_24 AC 560 ms
67,456 KB
testcase_25 AC 620 ms
67,328 KB
testcase_26 AC 281 ms
42,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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