結果

問題 No.517 壊れたアクセサリー
ユーザー nksk38nksk38
提出日時 2017-06-22 18:33:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 91,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 10:30:53
合計ジャッジ時間 1,905 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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,c;

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;
		}
	}

	if (s_size == 1) {
		cout << a[0] << endl;
		return 0;
	}

	string s;
	for (int j = 0; j < N; j++) {
		s = a[j];
		int used[30];
		for (int k = 0; k < N; k++)
			used[k] = 0;
		used[j] = 1;

		for (int i = 0; i < N; i++) {
			string str = "";
			str += s[s.size() - 1];
			str += a[i][0];
			if (used[i] == 0 && m[str] != 0) {
				s += a[i];
				m[str] = 1;
				used[i] = 1;
				if (s.size() == s_size) {
					cout << s << endl;
					return 0;
				}
			}
			str = "";
			str += a[i][a[i].size() - 1];
			str += s[0];
			if (used[i] == 0 && m[str] != 0) {
				s = a[i] + s;
				m[str] = 1;
				used[i] = 1;
				if (s.size() == s_size) {
					cout << s << endl;
					return 0;
				}
			}
		}
	}
	 cout << -1 << endl;
	return	0;
}
0