結果

問題 No.517 壊れたアクセサリー
ユーザー CleyLCleyL
提出日時 2023-06-06 08:45:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 796 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 82,744 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 10:38:26
合計ジャッジ時間 1,897 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main(){
  vector<int> a(26, -1);
  vector<int> a2(26, -1);
  set<int> b;
  for(int i = 0; 2 > i; i++){
    int n;cin>>n;
    for(int j = 0; n > j; j++){
      string s;cin>>s;
      for(int k = 0; s.size() > k; k++){
        if(k){
          a[s[k]-'A'] = s[k-1]-'A';
          a2[s[k-1]-'A'] = s[k]-'A';
        }
        b.insert(s[k]-'A');
      }
    }
  }
  string s = "";
  bool exist = false;
  for(int i = 0; 26 > i; i++){
    if(a[i] == -1 && b.count(i)){
      if(exist){
        cout << -1 << endl;
        return 0;
      }
      s.push_back(i+'A');
      int nw = i;
      while(a2[nw] != -1){
        nw = a2[nw];
        s.push_back(nw+'A');
      }
      exist = true;
    }
  }
  cout << s << endl;
}
0