結果

問題 No.429 CupShuffle
ユーザー incuiioincuiio
提出日時 2023-06-14 21:33:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 133,224 KB
実行使用メモリ 4,868 KB
最終ジャッジ日時 2023-09-05 07:10:11
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 80 ms
4,428 KB
testcase_12 AC 74 ms
4,432 KB
testcase_13 AC 80 ms
4,868 KB
testcase_14 AC 78 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>
#include <cassert>
#include <regex>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;

int main()
{
    int n, k, x;
    cin >> n >> k >> x;
    vector<int> begin_arr(n);
    for (int i = 0; i < n; i++)
    {
        begin_arr[i] = i + 1;
    }
    vector<int> end_a, end_b;
    bool is_begin = true;
    for (int i = 0; i < k; i++)
    {
        if (i == x - 1)
        {
            char a, b;
            cin >> a >> b;
            is_begin = false;
            continue;
        }
        int a, b;
        cin >> a >> b;
        if (is_begin)
        {
            std::swap(begin_arr[a-1], begin_arr[b-1]);
        }
        else
        {
            end_a.push_back(a-1);
            end_b.push_back(b-1);
        }
    }
    vector<int> end_arr(n);
    for (int i = 0; i < n; i++)
    {
        cin >> end_arr[i];
    }
    for (int i = end_a.size()-1; i >= 0; i--)
    {
        std::swap(end_arr[end_a[i]], end_arr[end_b[i]]);
    }
    int a, b;
    a = b = -1;
    for (int i = 0; i < n; i++)
    {
        if (begin_arr[i] != end_arr[i])
        {
            if (a == -1)
            {
                a = i+1;
            }
            else
            {
                b = i+1;
            }
        }
    }
    cout << a << ' ' << b << endl;
}
0