結果

問題 No.197 手品
ユーザー kyuridenamida
提出日時 2015-04-28 23:35:59
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 807 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 177,528 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 03:33:07
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long f(string s,string t,int N){
	queue< pair<int,string> > Q;
	map< pair<int,string> ,int> ok;
	Q.push({0,s});
	ok[{0,s}] = 0;
	while( Q.size() ){
		auto q = Q.front(); Q.pop();
		if( q.second == t && q.first == N ){
			return ok[q];
		}
		if( q.first > N ) continue;
		for(int i = 0 ; i < 3 ; i++)
			for(int j = i+1 ; j < 3 ; j++){
				if( j-i > 1 ) continue;
				string w = q.second;
				swap(w[i],w[j]);
				if( !ok.count({q.first+1,w}) ){
					ok[{q.first+1,w}] = ok[q] + 1;
					Q.push({q.first+1,w});
				}
			}
	}
	return 1e15;
}

int main(){
	string s,t;
	int N;
	cin >> s >> N >> t;
	if( N % 2 ) N = min(N,11);
	else N = min(N,10);
	long long r = f(s,t,N);
	if( r > N ) {
		cout << "SUCCESS" << endl;
	}else{
		cout << "FAILURE" << endl;
	}
	
}
0