結果

問題 No.429 CupShuffle
コンテスト
ユーザー lam6er
提出日時 2025-03-20 18:59:46
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 779 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 240 ms
コンパイル使用メモリ 96,236 KB
実行使用メモリ 116,324 KB
最終ジャッジ日時 2026-07-07 08:18:51
合計ジャッジ時間 3,421 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n, k_total, x = map(int, input().split())

operations = []
for _ in range(k_total):
    a, b = input().split()
    operations.append((a, b))

c = list(map(int, input().split()))

# Reconstruct S1: initial state up to X-1 exchanges
s1 = list(range(1, n + 1))
for k in range(1, x):
    a_str, b_str = operations[k - 1]
    a = int(a_str)
    b = int(b_str)
    s1[a-1], s1[b-1] = s1[b-1], s1[a-1]

# Reconstruct S2: final state after undoing exchanges after X
s2 = c.copy()
for k in range(k_total, x, -1):
    a_str, b_str = operations[k - 1]
    a = int(a_str)
    b = int(b_str)
    s2[a-1], s2[b-1] = s2[b-1], s2[a-1]

# Find differing positions
diff = []
for i in range(n):
    if s1[i] != s2[i]:
        diff.append(i + 1)  # 1-based index

diff.sort()
print(diff[0], diff[1])
0