結果

問題 No.429 CupShuffle
ユーザー かにかに
提出日時 2016-10-09 22:27:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,432 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 162,516 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 18:35:09
合計ジャッジ時間 2,981 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define Pi pair<int,int>
#define IINF 1e9
#define LINF 1e18
#define vi vector<int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 0, 1,0,-1 };
int dy[] = { 1, 0,-1,0 };

void isPrime(ll n) {
	if (n <= 1) {
		cout << "1 1" << endl;
		return;
	}
	if (n == 2) {
		cout << "2 1" << endl;
		return;
	}
	if (n % 2 == 0){
		cout << 2 << " " << n / 2 << endl;
		return;
	}	
	for (ll i = 3; i*i <= n; i += 2) {
		if (n%i == 0) {
			cout << i << " " << n / i << endl;
			return;
		}
	}
	cout << 1 << " " << n << endl;
	return;
}

void solve() {
	int n, k, x;
	cin >> n >> k >> x;
	vi a, b,c1,c2;
	rep(i, n) {
		c1.push_back(i + 1);
	}
	rep(i, k) {
		if (i != x - 1) {
			int A, B;
			cin >> A >> B;
			A--; B--;
			a.push_back(A);
			b.push_back(B);
		}
		else {
			char s1, s2;
			cin >> s1 >> s2;
			a.push_back(0);
			b.push_back(0);
		}
	}
	rep(i, n) {
		int A;
		cin >> A;
		c2.push_back(A);
	}

	rep(i, x-1) {
		swap(c1[a[i]], c1[b[i]]);
	}
	
	for (int i = k - 1; i >= x; i--) {
		swap(c2[a[i]], c2[b[i]]);
	}
	vi pos;
	rep(i, n) {
		if (c1[i] != c2[i])pos.push_back(i+1);
	}
	cout << pos[0] << " " << pos[1] << endl;
}

int main() {
	solve();
	return 0;
}
0