結果

問題 No.326 あみだますたー
ユーザー rlangevinrlangevin
提出日時 2023-02-22 12:43:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-29 20:48:08
合計ジャッジ時間 2,380 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,784 KB
testcase_01 AC 15 ms
7,936 KB
testcase_02 AC 16 ms
8,296 KB
testcase_03 AC 36 ms
8,564 KB
testcase_04 AC 19 ms
8,608 KB
testcase_05 AC 15 ms
7,772 KB
testcase_06 AC 26 ms
8,260 KB
testcase_07 AC 19 ms
7,852 KB
testcase_08 AC 24 ms
8,752 KB
testcase_09 AC 36 ms
8,696 KB
testcase_10 AC 35 ms
8,708 KB
testcase_11 AC 16 ms
7,860 KB
testcase_12 AC 25 ms
8,604 KB
testcase_13 AC 29 ms
8,612 KB
testcase_14 AC 17 ms
8,316 KB
testcase_15 AC 23 ms
7,768 KB
testcase_16 AC 28 ms
7,796 KB
testcase_17 AC 20 ms
8,464 KB
testcase_18 AC 21 ms
8,296 KB
testcase_19 AC 26 ms
8,224 KB
testcase_20 AC 16 ms
7,880 KB
testcase_21 AC 15 ms
7,924 KB
testcase_22 AC 26 ms
8,676 KB
testcase_23 AC 26 ms
8,668 KB
testcase_24 AC 32 ms
8,504 KB
testcase_25 AC 30 ms
8,584 KB
testcase_26 AC 18 ms
7,820 KB
testcase_27 AC 28 ms
8,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
K = int(input())
L = list(range(N))

for i in range(K):
    X, Y = map(int, input().split())
    X, Y = X - 1, Y - 1
    L[X], L[Y] = L[Y], L[X]

A = list(map(int, input().split()))
A = list(map(lambda x : x - 1, A))
D = [0] * N
for i in range(N):
    D[A[i]] = i

ans = []
for i in range(N):
    ind = L.index(D[i])
    for j in range(ind - 1, i - 1, -1):
        ans.append((j, j + 1))
        L[j], L[j + 1] = L[j + 1], L[j]

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)
0