結果

問題 No.326 あみだますたー
ユーザー MitI_7MitI_7
提出日時 2016-01-11 10:24:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,087 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 12,016 KB
実行使用メモリ 11,200 KB
最終ジャッジ日時 2023-10-19 22:46:23
合計ジャッジ時間 5,472 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,264 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 33 ms
10,276 KB
testcase_06 AC 53 ms
10,632 KB
testcase_07 AC 40 ms
10,380 KB
testcase_08 AC 54 ms
10,864 KB
testcase_09 AC 76 ms
11,200 KB
testcase_10 AC 72 ms
11,160 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 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 solve(now, target):
    ans = []
    t = target[-1]
    n = now.index(t) + 1
    for i in range(n, len(target)):
        ans.append((i, i + 1))

    return ans


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()))

    now = list(range(1, n + 1))
    now = sim(now, l)

    ans = []
    while True:
        new = solve(now, target)
        ans += new
        now = sim(now, new)

        now = now[:-1]
        target = target[:-1]
        if len(now) == 1:
            break

    print(len(ans))
    for a in ans:
        print(a[0], a[1])

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