結果
| 問題 | No.517 壊れたアクセサリー |
| コンテスト | |
| ユーザー |
mogurocker
|
| 提出日時 | 2017-10-16 02:01:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,135 bytes |
| 記録 | |
| コンパイル時間 | 1,552 ms |
| コンパイル使用メモリ | 159,600 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 18:58:34 |
| 合計ジャッジ時間 | 1,710 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 14 WA * 1 |
ソースコード
#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;
}
mogurocker