結果

問題 No.429 CupShuffle
ユーザー HachimoriHachimori
提出日時 2016-10-02 22:53:11
言語 Python2
(2.7.18)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 1,076 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 6,528 KB
実行使用メモリ 33,472 KB
最終ジャッジ日時 2023-08-13 17:15:21
合計ジャッジ時間 2,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,004 KB
testcase_01 AC 11 ms
5,904 KB
testcase_02 AC 11 ms
5,908 KB
testcase_03 AC 11 ms
5,824 KB
testcase_04 AC 13 ms
5,912 KB
testcase_05 AC 11 ms
6,016 KB
testcase_06 AC 13 ms
6,140 KB
testcase_07 AC 14 ms
6,092 KB
testcase_08 AC 11 ms
6,040 KB
testcase_09 AC 14 ms
6,044 KB
testcase_10 AC 47 ms
8,692 KB
testcase_11 AC 404 ms
33,224 KB
testcase_12 AC 378 ms
33,472 KB
testcase_13 AC 398 ms
32,616 KB
testcase_14 AC 396 ms
32,616 KB
testcase_15 AC 11 ms
5,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8

def read():
    nNum, nSwap, hiddenSwap = map(int, raw_input().split())

    swapList = []
    for i in range(nSwap):
        if i + 1 != hiddenSwap:
            swapList.append(map(int, raw_input().split()))
        else:
            raw_input()
            swapList.append([-1, -1])

    lastState = map(int, raw_input().split())

    return nNum, swapList, hiddenSwap, lastState


def work((nNum, swapList, hiddenSwap, lastState)):
    state1 = [i + 1 for i in range(nNum)]
    for (idx, (s, t)) in enumerate(swapList):
        if idx + 1 == hiddenSwap:
            break
        state1[s - 1], state1[t - 1] = state1[t - 1], state1[s - 1]
    
    state2 = lastState
    for idx in range(len(swapList))[::-1]:
        if idx + 1 == hiddenSwap:
            break
        s, t = swapList[idx]
        state2[s - 1], state2[t - 1] = state2[t - 1], state2[s - 1]

    ans = []
    for i in range(nNum):
        if state1[i] != state2[i]:
            ans.append(i + 1)

    print ans[0], ans[1]


if __name__ == "__main__":
    work(read())
0