結果

問題 No.517 壊れたアクセサリー
ユーザー mogurockermogurocker
提出日時 2017-10-16 02:01:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,135 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 146,316 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 05:27:41
合計ジャッジ時間 2,563 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, m;
char nex[30];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	fill(nex, nex+30, 'z');
	bool ok = true;
	int cnt = 0;
	FOR(i, n) {
		string s;
		cin >> s;
		cnt += s.size();
		FOR(j, s.size()-1) {
			if (nex[s[j]-'A'] == 'z') nex[s[j]-'A'] = s[j+1];
			else if (nex[s[j]-'A'] != s[j+1]) ok = false;
		}
	}
	cin >> m;
	FOR(i, m) {
		string s;
		cin >> s;
		FOR(j, s.size()-1) {
			if (nex[s[j]-'A'] == 'z') nex[s[j]-'A'] = s[j+1];
			else if (nex[s[j]-'A'] != s[j+1]) ok = false;
		}
	}
	int cnt2 = 0;
	FOR(i, 26) {
		if (nex[i] != 'z') cnt2++;
	}
	if (!ok || cnt != cnt2+1) {
		cout << -1 << endl;
		return 0;
	}
	FOR(i, 26) {
		string ret = "";
		for (char c = (char)('A'+i); c != 'z'; c = nex[c-'A']) {
			ret += string(1, c);
		}
		if (ret.size() == cnt) {
			cout << ret << endl;
			return 0;
		}
	}
	return 0;
}
0