結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
hiyokko2
|
| 提出日時 | 2017-05-28 21:53:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,187 bytes |
| コンパイル時間 | 726 ms |
| コンパイル使用メモリ | 82,020 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-09-21 15:24:05 |
| 合計ジャッジ時間 | 4,367 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 TLE * 1 -- * 4 |
ソースコード
//#define LOCAL
#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#define int long long
//typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int N, M;
string in[52];
int len;
string ans;
void dfs(string str)
{
if (str.length() > ans.length()) {
ans = str;
//cout << "ans = " << ans << endl;
}
char fst = str[0];
char lst = str[str.length()-1];
rep(i, N + M) {
if (in[i].find(fst) != string::npos && in[i].find(fst) >= 1) {
dfs(in[i].substr(0, in[i].find(fst)) + str);
}
if (in[i].find(lst) != string::npos && in[i].find(lst) < in[i].length() - 1) {
dfs(str + in[i].substr(in[i].find(lst) + 1));
}
}
}
signed main()
{
#ifdef LOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
cin >> N;
rep(i,N) {
cin >> in[i];
len += in[i].length();
}
cin >> M;
rep(i,M) cin >> in[N+i];
dfs(in[0]);
if (ans.length() == len) {
cout << ans << endl;
} else {
cout << -1 << endl;
}
}
hiyokko2