結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-22 17:17:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,278 bytes |
| コンパイル時間 | 955 ms |
| コンパイル使用メモリ | 91,412 KB |
| 実行使用メモリ | 13,636 KB |
| 最終ジャッジ日時 | 2024-10-02 12:19:26 |
| 合計ジャッジ時間 | 4,899 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 TLE * 1 -- * 5 |
ソースコード
#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;
}