結果

問題 No.326 あみだますたー
ユーザー finefine
提出日時 2016-06-05 01:29:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 11,376 KB
実行使用メモリ 15,392 KB
最終ジャッジ日時 2023-08-27 06:17:38
合計ジャッジ時間 4,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,248 KB
testcase_01 AC 76 ms
15,104 KB
testcase_02 AC 76 ms
15,172 KB
testcase_03 AC 84 ms
15,392 KB
testcase_04 AC 77 ms
15,100 KB
testcase_05 AC 80 ms
15,076 KB
testcase_06 AC 81 ms
15,272 KB
testcase_07 AC 77 ms
15,168 KB
testcase_08 AC 81 ms
15,228 KB
testcase_09 AC 88 ms
15,164 KB
testcase_10 AC 88 ms
15,324 KB
testcase_11 AC 80 ms
15,048 KB
testcase_12 AC 83 ms
15,160 KB
testcase_13 AC 84 ms
15,160 KB
testcase_14 AC 80 ms
15,096 KB
testcase_15 AC 82 ms
15,240 KB
testcase_16 AC 84 ms
15,352 KB
testcase_17 AC 83 ms
15,272 KB
testcase_18 AC 81 ms
15,212 KB
testcase_19 AC 81 ms
15,100 KB
testcase_20 AC 76 ms
15,200 KB
testcase_21 AC 76 ms
15,252 KB
testcase_22 AC 84 ms
15,240 KB
testcase_23 AC 84 ms
15,208 KB
testcase_24 AC 86 ms
15,292 KB
testcase_25 AC 85 ms
15,224 KB
testcase_26 AC 80 ms
15,172 KB
testcase_27 AC 83 ms
15,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
k = gets.to_i
a = [*0...n]
k.times{
    x, y = gets.split.map(&:to_i)
    x -= 1
    y -= 1
    tmp = a[x]
    a[x] = a[y]
    a[y] = tmp
    }
b = gets.split.map(&:to_i)
ans = []
n.times{|i|
    1.upto(n - i - 1){|j|
        if b[a[j]] < b[a[j - 1]]
            tmp = a[j]
            a[j] = a[j - 1]
            a[j - 1] = tmp
            ans.push(j)
        end
        }
    }
s = ans.size
p s
s.times{|i|
    puts "#{ans[i]} #{ans[i] + 1}"
    }
0