結果

問題 No.326 あみだますたー
ユーザー finefine
提出日時 2016-06-04 22:15:52
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 527 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-17 00:29:38
合計ジャッジ時間 8,296 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
12,288 KB
testcase_01 AC 93 ms
12,160 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 101 ms
12,288 KB
testcase_05 AC 93 ms
12,032 KB
testcase_06 WA -
testcase_07 AC 99 ms
12,288 KB
testcase_08 AC 103 ms
12,416 KB
testcase_09 WA -
testcase_10 AC 113 ms
12,416 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
k = gets.to_i
a = [*1..n]
k.times{
    x, y = gets.split.map(&:to_i)
    x -= 1
    y -= 1
    tmp = a[x]
    a[x] = a[y]
    a[y] = tmp
    }
c = gets.split.map(&:to_i)
b = Array.new(n + 1)
n.times{|i|
    b[c[i]] = i
    }
ans = []
(n - 1).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.unshift(j)
        end
        }
    }
s = ans.size
p s
s.times{|i|
    puts "#{ans[i]} #{ans[i] + 1}"
    }
0