結果

問題 No.326 あみだますたー
ユーザー htkbhtkb
提出日時 2019-02-08 11:16:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 595 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2023-09-09 23:06:11
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,052 KB
testcase_01 AC 17 ms
8,072 KB
testcase_02 AC 19 ms
7,976 KB
testcase_03 AC 35 ms
8,688 KB
testcase_04 AC 21 ms
8,408 KB
testcase_05 AC 16 ms
8,060 KB
testcase_06 AC 27 ms
8,316 KB
testcase_07 AC 20 ms
8,136 KB
testcase_08 AC 24 ms
8,668 KB
testcase_09 AC 36 ms
8,772 KB
testcase_10 AC 36 ms
8,832 KB
testcase_11 AC 16 ms
8,076 KB
testcase_12 AC 26 ms
8,464 KB
testcase_13 AC 30 ms
8,460 KB
testcase_14 AC 19 ms
8,544 KB
testcase_15 AC 23 ms
8,048 KB
testcase_16 AC 28 ms
8,408 KB
testcase_17 AC 22 ms
8,556 KB
testcase_18 AC 22 ms
8,576 KB
testcase_19 AC 26 ms
8,468 KB
testcase_20 AC 17 ms
8,012 KB
testcase_21 AC 17 ms
8,072 KB
testcase_22 AC 27 ms
8,592 KB
testcase_23 AC 27 ms
8,540 KB
testcase_24 AC 33 ms
8,520 KB
testcase_25 AC 30 ms
8,696 KB
testcase_26 AC 19 ms
8,332 KB
testcase_27 AC 28 ms
8,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
N = int(input())
K = int(input())
V = list(range(N+1))

for x, y in (map(int, input().split()) for _ in [0]*K):
    V[x], V[y] = V[y], V[x]

goal, _ = zip(*sorted(enumerate(map(int, input().split()), start=1), key=itemgetter(1)))
ans = []

for i, v in enumerate(goal, start=1):
    pos = V.index(v)
    if i == pos:
        continue
    r = zip(range(pos-1, i-1, -1), range(pos, i, -1)) if i < pos else zip(range(i, pos), range(i+1, pos+1))
    for j, k in r:
        ans.append((j, k))
        V[j], V[k] = V[k], V[j]

print(len(ans))
for l in ans:
    print(*l)
0