結果

問題 No.429 CupShuffle
ユーザー Mister
提出日時 2020-04-14 17:57:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 79,800 KB
最終ジャッジ日時 2025-01-09 18:47:29
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

void solve() {
    int n, k, x;
    std::cin >> n >> k >> x;

    std::vector<int> xs(n);
    std::iota(xs.begin(), xs.end(), 0);

    std::vector<std::pair<int, int>> ps;
    for (int i = 1; i <= k; ++i) {
        if (i == x) {
            char a, b;
            std::cin >> a >> b;
            continue;
        }

        int a, b;
        std::cin >> a >> b;
        --a, --b;

        if (i < x) {
            std::swap(xs[a], xs[b]);
        } else {
            ps.emplace_back(a, b);
        }
    }

    std::vector<int> ys(n);
    for (auto& y : ys) {
        std::cin >> y;
        --y;
    }

    std::reverse(ps.begin(), ps.end());
    for (auto p : ps) {
        std::swap(ys[p.first], ys[p.second]);
    }

    for (int i = 0; i < n; ++i) {
        if (xs[i] != ys[i]) std::cout << i + 1 << " ";
    }
    std::cout << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0