結果

問題 No.429 CupShuffle
ユーザー tabataba
提出日時 2017-05-18 20:39:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 116,288 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-10-18 23:13:23
合計ジャッジ時間 2,322 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <random>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <utility>
#include <regex>
#include <tuple>
#include <map>

using namespace std;

int main(){
	int n,k,x;
	-scanf("%d%d%d",&n,&k,&x);
	vector<array<int,2>> ab(k);
	for(int i=0;i<k;i++){
		char as[10],bs[10];
		-scanf("%s %s",as,bs);
		int a,b;
		if(as[0]=='?'){
			a=b=-1;
		}else{
			a=stoi(as)-1;
			b=stoi(bs)-1;
		}
		ab[i][0]=a;
		ab[i][1]=b;
	}
	vector<int> c(n);
	for(int i=0;i<n;i++){
		-scanf("%d",&c[i]);
	}
	vector<int> start(n);
	for(int i=0;i<n;i++){
		start[i]=i+1;
	}
	for(int i=0;i<x;i++){
		swap(start[ab[i][0]],start[ab[i][1]]);
	}
	for(int i=k-1;i>=x;i--){
		swap(c[ab[i][0]],c[ab[i][1]]);
	}
	vector<int> abx;
	for(int i=0;i<n;i++){
		//printf("%d %d\n",start[i],c[i]);
		if(start[i]!=c[i]){
			abx.push_back(i+1);
		}
	}
	//printf("%lu\n",abx.size());
	assert(abx.size()==2);
	printf("%d %d\n",abx[0],abx[1]);
	return 0;
}
0