結果

問題 No.429 CupShuffle
ユーザー newlife171128newlife171128
提出日時 2018-01-15 23:11:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 4,972 KB
最終ジャッジ日時 2023-08-25 17:59:36
合計ジャッジ時間 2,104 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>

typedef long long ll;

using namespace std;

int start[100001];
int finsh_line[100001];

int main() {

	int n, k, x;
	cin >> n >> k >> x;

	for (int i = 1; i <= n; i++) {
		start[i] = i;
	}

	stack<pair<int, int> > st;

	int l = 0, r = 0;
	for (int i = 1; i <= k; i++) {
		if (i < x) {
			cin >> l >> r;

			int tmp = start[l];

			start[l] = start[r];

			start[r] = tmp;

		}

		if (i == x) {
			string s;
			cin >> s >> s;
		}

		if (i > x) {
			cin >> l >> r;

			pair<int, int> pr;
			pr = make_pair(l, r);

			st.push(pr);

		}

	}
	for (int i = 1; i <= n; i++) {
		int tmp = 0;
		cin >> tmp;
		finsh_line[i] = tmp;
	}

	for (int i = 0; i < k - x; i++) {
		pair<int, int> pr;

		pr = st.top();
		st.pop();

		int tmp = finsh_line[pr.first];

		finsh_line[pr.first] = finsh_line[pr.second];

		finsh_line[pr.second] = tmp;
	}

	int ans_l = 0, ans_r = 0;
	for (int i = 1; i <= n; i++) {

		if (start[i] != finsh_line[i]) {

			if (ans_l == 0) {
				ans_l = i;
			} else {
				ans_r = i;
			}

		}
	}

	cout << ans_l << " " << ans_r << endl;

	return 0;
}
0