結果
問題 | No.517 壊れたアクセサリー |
ユーザー |
![]() |
提出日時 | 2017-05-31 00:23:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 607 bytes |
コンパイル時間 | 439 ms |
コンパイル使用メモリ | 57,676 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-21 19:25:35 |
合計ジャッジ時間 | 1,156 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
ソースコード
#include <iostream> #include <sstream> using namespace std; int main(int argc, char *argv[]) { int n, len = 0; int c[256] = {}; string s; for (int t = 0; t < 2; ++t) { len = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> s; for (int j = 1; j != s.length(); ++j) { c[s[j-1]] = s[j]; } len += s.length(); } } string ans = "-1"; if (len == 1) { ans = s; } else { for (int i = 'A'; i <= 'Z'; ++i) { s = ""; char x = i; while (x) { s += x; x = c[x]; } if (s.length() == len) { ans = s; break; } } } cout << ans << endl; return 0; }