結果

問題 No.326 あみだますたー
ユーザー yozayoza
提出日時 2015-12-19 21:51:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 11,228 KB
実行使用メモリ 15,352 KB
最終ジャッジ日時 2023-08-27 01:28:51
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,084 KB
testcase_01 AC 72 ms
15,292 KB
testcase_02 AC 75 ms
15,160 KB
testcase_03 AC 86 ms
15,300 KB
testcase_04 AC 84 ms
15,068 KB
testcase_05 AC 80 ms
15,056 KB
testcase_06 AC 83 ms
15,120 KB
testcase_07 AC 78 ms
15,184 KB
testcase_08 AC 79 ms
15,244 KB
testcase_09 AC 87 ms
15,172 KB
testcase_10 AC 87 ms
15,352 KB
testcase_11 AC 75 ms
15,004 KB
testcase_12 AC 86 ms
15,172 KB
testcase_13 AC 87 ms
15,348 KB
testcase_14 AC 83 ms
15,124 KB
testcase_15 AC 82 ms
15,164 KB
testcase_16 AC 86 ms
15,232 KB
testcase_17 AC 81 ms
15,296 KB
testcase_18 AC 77 ms
15,184 KB
testcase_19 AC 81 ms
15,348 KB
testcase_20 AC 74 ms
15,128 KB
testcase_21 AC 74 ms
15,000 KB
testcase_22 AC 83 ms
15,260 KB
testcase_23 AC 82 ms
15,204 KB
testcase_24 AC 85 ms
15,204 KB
testcase_25 AC 81 ms
15,348 KB
testcase_26 AC 81 ms
15,156 KB
testcase_27 AC 86 ms
15,252 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
k = gets.to_i
amida = n.times.map {|i| i}
k.times do
  x, y = gets.chomp.split.map {|i| i.to_i - 1}
  amida[x], amida[y] = amida[y], amida[x]
end

a_list = Array.new(n)
gets.chomp.split.each_with_index {|a, i| a_list[a.to_i - 1] = i}
b_list = []

a_list.each_with_index do |a, i|
  dest_index = amida.find_index(a)
  next if dest_index == i
  amida.delete_at(dest_index)
  amida.insert(i, a)
  dest_index.downto(i+1) {|k| b_list.push "#{k} #{k+1}"}
end

puts b_list.length
b_list.each {|b| puts b}
0