結果

問題 No.326 あみだますたー
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-01-17 19:49:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 8,876 KB
最終ジャッジ日時 2023-08-24 16:40:17
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,156 KB
testcase_01 AC 16 ms
8,236 KB
testcase_02 AC 18 ms
8,344 KB
testcase_03 AC 35 ms
8,576 KB
testcase_04 AC 19 ms
8,640 KB
testcase_05 AC 16 ms
8,236 KB
testcase_06 AC 27 ms
8,248 KB
testcase_07 AC 20 ms
8,312 KB
testcase_08 AC 23 ms
8,776 KB
testcase_09 AC 35 ms
8,872 KB
testcase_10 AC 36 ms
8,876 KB
testcase_11 AC 16 ms
8,260 KB
testcase_12 AC 26 ms
8,572 KB
testcase_13 AC 29 ms
8,588 KB
testcase_14 AC 18 ms
8,312 KB
testcase_15 AC 24 ms
8,244 KB
testcase_16 AC 28 ms
8,308 KB
testcase_17 AC 22 ms
8,516 KB
testcase_18 AC 21 ms
8,524 KB
testcase_19 AC 25 ms
8,272 KB
testcase_20 AC 16 ms
8,312 KB
testcase_21 AC 16 ms
8,232 KB
testcase_22 AC 27 ms
8,516 KB
testcase_23 AC 25 ms
8,660 KB
testcase_24 AC 32 ms
8,616 KB
testcase_25 AC 29 ms
8,736 KB
testcase_26 AC 19 ms
8,176 KB
testcase_27 AC 28 ms
8,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import itertools


def main():
    n = int(input())
    k = int(input())
    target = list(range(n))
    for _ in range(k):
        x, y = (int(w) - 1 for w in input().split())
        target[x], target[y] = target[y], target[x]
    zs = [int(z) - 1 for z in input().split()]
    for i in range(n):
        target[i] = zs[target[i]]
    ans = []
    for _, j in itertools.product(range(n), range(n - 1)):
        if target[j] > target[j + 1]:
            target[j], target[j + 1] = target[j + 1], target[j]
            ans.append((j, j + 1))
    print(len(ans))
    for x, y in ans:
        print(x + 1, y + 1)


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