結果

問題 No.429 CupShuffle
ユーザー Yut176Yut176
提出日時 2016-10-02 22:51:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 67,708 KB
実行使用メモリ 4,656 KB
最終ジャッジ日時 2023-08-13 17:14:49
合計ジャッジ時間 2,062 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

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

	vector<int> a1(x-1);
	vector<int> b1(x-1);

	vector<int> a2(k-x);
	vector<int> b2(k-x);
	char q[2];

	for(int i=0; i<x-1; i++) cin >> a1[i] >> b1[i];

	cin >> q[0] >> q[1];

	for(int i=0; i<k-x; i++) cin >> a2[i] >> b2[i];

	vector<int> c(n);
	vector<int> t(n);
	for(int i=0; i<n; i++){
		cin >> c[i];
		t[i] = i+1;
	}

	for(int i=0; i<x-1; i++){
		int tmp;
		tmp = t[ a1[i]-1 ];
		t[ a1[i]-1 ] = t[ b1[i]-1 ];
		t[ b1[i]-1 ] = tmp;
	}

	for(int i=k-x-1; i>=0; i--){
		int tmp;
		tmp = c[ a2[i]-1 ];
		c[ a2[i]-1 ] = c[ b2[i]-1 ];
		c[ b2[i]-1 ] = tmp;
	}
	int ans[2];
	int j=0;
	for(int i=0; i<n; i++){
		if( t[i] != c[i] ){
			ans[j] = i+1;
			j++;
			if( j == 2 ) break;
		}
	}
	if( ans[0] < ans[1] ) cout << ans[0] << " " << ans[1] << endl;
	else cout << ans[1] << " " << ans[0] << endl;

	

	return 0;
}
0