結果

問題 No.429 CupShuffle
ユーザー startcppstartcpp
提出日時 2016-01-06 16:05:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,088 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 59,612 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-10-19 16:09:02
合計ジャッジ時間 4,509 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//1-indexedな愚直解
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int n, k, x;
int a[100001], b[100001];
int c[100001];

bool isOk(){
	int i;
	static int d[100001];	//シミュレーション用、d[i]=位置iにあるコップ
	
	for( i = 1; i <= n; i++ ){
		d[i] = i;
	}
	
	for( i = 1; i <= k; i++ ){
		swap(d[a[i]], d[b[i]]);
	}
	
	for( i = 1; i <= n; i++ ){
		//合っていなければfalseを返す
		if( c[i] != d[i] ){
			return false;
		}
	}
	//正解.やったね!
	return true;
}

int main()
{
	int i, j;
	
	cin >> n >> k >> x;
	for( i = 1; i <= k; i++ ){
		if( i == x ){
			string yuki, coder;
			cin >> yuki >> coder;
		}
		else{
			cin >> a[i] >> b[i];
		}
	}
	for( i = 1; i <= n; i++ ){
		cin >> c[i];
	}
	
	for( i = 1; i <= n; i++ ){
		for( j = i + 1; j <= n; j++ ){
			//?を埋めてみる
			a[x] = i;
			b[x] = j;
			//シミュレーションする→正解かどうか判定する
			if( isOk() ){
				cout << a[x] << " " << b[x] << endl;
				return 0;
			}
		}
	}
	cout << "答えがない!訴訟!" << endl;
	return 0;
}
0