結果

問題 No.326 あみだますたー
ユーザー code-devocode-devo
提出日時 2016-01-07 01:24:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 365 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 11,168 KB
実行使用メモリ 15,864 KB
最終ジャッジ日時 2023-08-27 06:09:51
合計ジャッジ時間 4,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
14,976 KB
testcase_01 AC 83 ms
15,080 KB
testcase_02 AC 86 ms
15,092 KB
testcase_03 AC 97 ms
15,320 KB
testcase_04 AC 90 ms
15,376 KB
testcase_05 AC 83 ms
14,976 KB
testcase_06 AC 91 ms
15,160 KB
testcase_07 AC 88 ms
15,216 KB
testcase_08 AC 94 ms
15,864 KB
testcase_09 AC 100 ms
15,496 KB
testcase_10 AC 102 ms
15,628 KB
testcase_11 AC 85 ms
15,080 KB
testcase_12 AC 91 ms
15,204 KB
testcase_13 AC 93 ms
15,232 KB
testcase_14 AC 88 ms
15,160 KB
testcase_15 AC 90 ms
15,316 KB
testcase_16 AC 91 ms
15,208 KB
testcase_17 AC 89 ms
15,292 KB
testcase_18 AC 88 ms
15,204 KB
testcase_19 AC 91 ms
15,144 KB
testcase_20 AC 83 ms
15,212 KB
testcase_21 AC 84 ms
15,108 KB
testcase_22 AC 94 ms
15,332 KB
testcase_23 AC 91 ms
15,208 KB
testcase_24 AC 96 ms
15,168 KB
testcase_25 AC 94 ms
15,336 KB
testcase_26 AC 86 ms
15,232 KB
testcase_27 AC 90 ms
15,324 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
a = Array.new(n+1){|i| i}
gets.to_i.times do
  x, y = gets.split.map(&:to_i)
  a[x], a[y] = a[y], a[x]
end

w = gets.split.map(&:to_i).unshift(0)

ans = []
(n-1).downto(1) do |to|
  for i in 1..to do
    if w[a[i]] > w[a[i+1]] then
      ans << [i, i+1]
      a[i], a[i+1] = a[i+1], a[i]
    end
  end
end

puts ans.size
puts ans.map{|a| a.join(" ")}
0