結果

問題 No.326 あみだますたー
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-19 04:03:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 8,548 KB
最終ジャッジ日時 2023-08-07 18:27:09
合計ジャッジ時間 2,312 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,744 KB
testcase_01 AC 15 ms
7,908 KB
testcase_02 AC 17 ms
8,184 KB
testcase_03 AC 35 ms
8,380 KB
testcase_04 AC 19 ms
8,344 KB
testcase_05 AC 15 ms
7,816 KB
testcase_06 AC 25 ms
7,860 KB
testcase_07 AC 19 ms
7,852 KB
testcase_08 AC 22 ms
8,520 KB
testcase_09 AC 36 ms
8,416 KB
testcase_10 AC 34 ms
8,380 KB
testcase_11 AC 15 ms
7,820 KB
testcase_12 AC 25 ms
8,408 KB
testcase_13 AC 30 ms
8,436 KB
testcase_14 AC 18 ms
8,412 KB
testcase_15 AC 22 ms
7,936 KB
testcase_16 AC 28 ms
7,760 KB
testcase_17 AC 21 ms
8,400 KB
testcase_18 AC 20 ms
8,336 KB
testcase_19 AC 26 ms
7,860 KB
testcase_20 AC 15 ms
7,776 KB
testcase_21 AC 15 ms
7,812 KB
testcase_22 AC 26 ms
8,420 KB
testcase_23 AC 23 ms
8,548 KB
testcase_24 AC 32 ms
8,380 KB
testcase_25 AC 29 ms
8,444 KB
testcase_26 AC 17 ms
7,804 KB
testcase_27 AC 27 ms
8,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
K = int(input())
amida = list(range(N))
for k in range(K):
    x, y = map(int, input().split())
    amida[x-1], amida[x] = amida[x], amida[x-1]
As = list(map(int, input().split()))
Bs = [0] * N
for i, a in enumerate(As):
    Bs[a - 1] = i

move = []
for i, b in enumerate(Bs):
    pos = amida.index(b)
    while pos > i:
        move.append(pos)
        amida[pos], amida[pos - 1] = amida[pos - 1], amida[pos]
        pos -= 1
print(len(move))
for p in move:
    print(p, p + 1)
0