結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-28 22:15:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,099 bytes |
| コンパイル時間 | 1,608 ms |
| コンパイル使用メモリ | 169,184 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 15:32:34 |
| 合計ジャッジ時間 | 2,344 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int root[26];
int nex[26];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int m;
cin >> m;
vector<string> b(m);
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < 26; i++) {
root[i] = -1;
nex[i] = -1;
}
for (int i = 0; i < n; i++) {
if (root[a[i][0] - 'A'] == -1) root[a[i][0] - 'A'] = 1;
for (int j = 0; j + 1 < a[i].length(); j++) {
root[a[i][j + 1] - 'A'] = 0;
nex[a[i][j] - 'A'] = a[i][j + 1] - 'A';
}
}
for (int i = 0; i < m; i++) {
if (root[b[i][0] - 'A'] == -1) root[b[i][0] - 'A'] = 1;
for (int j = 0; j + 1 < b[i].length(); j++) {
root[b[i][j + 1] - 'A'] = 0;
nex[b[i][j] - 'A'] = b[i][j + 1] - 'A';
}
}
int idx = -1;
for (int i = 0; i < 26; i++) {
if (root[i] == 1) {
if (idx == -1) idx = i;
else {
idx = -1;
break;
}
}
}
if (idx == -1) {
cout << -1 << endl;
return 0;
}
for (int i = idx; i != -1; i = nex[i]) {
cout << (char)('A' + i);
}
cout << endl;
return 0;
}