結果

問題 No.429 CupShuffle
ユーザー MisterMister
提出日時 2020-04-14 17:57:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 83,672 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 14:09:26
合計ジャッジ時間 2,243 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 30 ms
6,940 KB
testcase_12 AC 28 ms
6,944 KB
testcase_13 AC 31 ms
6,944 KB
testcase_14 AC 30 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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