結果

問題 No.517 壊れたアクセサリー
ユーザー nksk38nksk38
提出日時 2017-06-22 17:17:07
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,278 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 91,692 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-10 10:30:05
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int N,M,s_size;
map<string, int> m;
vector<string> a, b;
queue<string> q;
int used[100];

int f(int n) {
	int num = 1;
	for (int i = 1; i <= n; i++)
		num *= i;
	return num;
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		a.push_back(s);
		s_size += s.size();
		for (int j = 0; j < s.size() - 1; j++) {
			string str = "";
			str += s[j],str+= s[j+1];
			m[str] = 1;
		}
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		string s;
		cin >> s;
		b.push_back(s);
		for (int j = 0; j < s.size() - 1; j++) {
			string str = "";
			str += s[j],str+= s[j + 1];
			m[str] = 1;
		}
	}

	for (int i = 0; i < f(N); i++) {
		string s;
		bool flag = true;
		for (auto x : a) {
			s += x;
		}
		for (int j = 0; j < s.size()-1; j++) {
			string str = "";
			str += s[j];
			str += s[j + 1];
			if (m[str] == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			cout << s << endl;
			return 0;
		}
		next_permutation(a.begin(), a.end());
	}
	cout << -1 << endl;
	return	0;
}
0