結果

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

テストケース

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

ソースコード

diff #

//0-indexedな愚直解(入力値の変更あり)
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

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

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

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