結果

問題 No.326 あみだますたー
ユーザー MitI_7MitI_7
提出日時 2016-01-11 12:06:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-25 12:01:14
合計ジャッジ時間 2,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,880 KB
testcase_01 AC 28 ms
11,008 KB
testcase_02 AC 30 ms
11,008 KB
testcase_03 AC 68 ms
11,648 KB
testcase_04 AC 31 ms
11,136 KB
testcase_05 AC 27 ms
10,880 KB
testcase_06 AC 49 ms
11,136 KB
testcase_07 AC 35 ms
10,880 KB
testcase_08 AC 34 ms
11,264 KB
testcase_09 AC 63 ms
11,776 KB
testcase_10 AC 55 ms
11,520 KB
testcase_11 AC 29 ms
11,008 KB
testcase_12 AC 42 ms
11,392 KB
testcase_13 AC 54 ms
11,392 KB
testcase_14 AC 28 ms
11,136 KB
testcase_15 AC 37 ms
11,008 KB
testcase_16 AC 39 ms
11,136 KB
testcase_17 AC 34 ms
11,136 KB
testcase_18 AC 34 ms
11,264 KB
testcase_19 AC 41 ms
11,264 KB
testcase_20 AC 24 ms
11,008 KB
testcase_21 AC 25 ms
10,880 KB
testcase_22 AC 45 ms
11,392 KB
testcase_23 AC 42 ms
11,392 KB
testcase_24 AC 59 ms
11,648 KB
testcase_25 AC 53 ms
11,392 KB
testcase_26 AC 30 ms
10,880 KB
testcase_27 AC 46 ms
11,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def bubble_sort(target):
    ans = []
    for n in range(len(target) - 1, 0, -1):
        for i in range(n):
            if target[i] > target[i + 1]:
                ans.append((i + 1, i + 2))
                target[i], target[i + 1] = target[i + 1], target[i]

    return ans[::-1]


def sim(now, line):
    m = dict()
    for i in range(1, len(now) + 1):
        no = i
        for x, y in line:
            if no == x:
                no = y
            elif no == y:
                no = x
        # now[i - 1]番は棒noに
        m[no] = now[i - 1]
    to = []
    for k, v in sorted(m.items()):
        to.append(v)
    return to


def main():
    n = int(input())
    k = int(input())
    l = []
    for _ in range(k):
        x, y = map(int, input().split())
        l.append((x, y))
    target = list(map(int, input().split()))

    to = sim(list(range(1, n + 1)), l)
    m = dict()
    for i in range(1, len(to) + 1):
        m[to[i - 1]] = i

    t = sorted([(x, i) for i, x in enumerate(target, start=1)])
    t = [m[x] for i, x in t]

    ans = bubble_sort(t)
    print(len(ans))
    for x in ans:
        print(x[0], x[1])

if __name__ == '__main__':
    main()
0