結果

問題 No.326 あみだますたー
ユーザー 小指が強い人小指が強い人
提出日時 2015-12-19 01:30:08
言語 Ruby
(3.4.1)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-11-07 23:18:51
合計ジャッジ時間 4,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: assigned but unused variable - s2
Syntax OK

ソースコード

diff #

n = gets.to_i
k = gets.to_i
a = Array.new(n)
b = Array.new(n)
x = Array.new(n)
y = Array.new(n)
n.times do |i|
    a[i] = i + 1
end
k.times do
    s1, s2 = gets.split.map(&:to_i)
    a[s1 - 1], a[s1] = a[s1], a[s1 - 1]
end
b = gets.split.map(&:to_i)
n.times do |i|
    x[a[i] - 1] = i + 1
    y[b[i] - 1] = i + 1
end
res = Array.new(2).map{Array.new}
n.times do |i|
    next if a[i] == y[i]
    j = 0
    while y[i] != a[j]
        j += 1
    end
    while i != j
        a[j], a[j - 1] = a[j - 1], a[j]
        res[0].push(j)
        res[1].push(j + 1)
        j -= 1
    end
end
puts res[0].length
res[0].length.times do |i|
    print res[0][i], " ", res[1][i], "\n"
end
0