結果

問題 No.326 あみだますたー
ユーザー MitI_7MitI_7
提出日時 2016-01-11 11:33:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,117 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 12,060 KB
実行使用メモリ 11,172 KB
最終ジャッジ日時 2023-10-19 22:47:33
合計ジャッジ時間 4,995 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,252 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 31 ms
10,256 KB
testcase_06 AC 51 ms
10,608 KB
testcase_07 AC 39 ms
10,356 KB
testcase_08 AC 36 ms
10,856 KB
testcase_09 AC 66 ms
11,132 KB
testcase_10 AC 60 ms
11,172 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 -
権限があれば一括ダウンロードができます

ソースコード

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 = [m[x] for x in target]
    ans = bubble_sort(t)
    print(len(ans))
    for x in ans:
        print(x[0], x[1])

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