結果

問題 No.517 壊れたアクセサリー
ユーザー albicillaalbicilla
提出日時 2017-05-28 21:53:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 1,922 ms
コンパイル使用メモリ 162,508 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 14:09:35
合計ジャッジ時間 2,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

typedef pair<int,int> P;

int n,m,len;
string a[30],b[30];
int nextt[30];
int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
    len+=a[i].size();
  }
  cin>>m;
  rep(i,m){
    cin>>b[i];
  }

  rep(i,30)nextt[i]=-1;

  //cout<<a[0][1]-'A'<<endl;
   rep(i,n){
     for(int j=0;j<a[i].size()-1;j++){
       nextt[a[i][j]-'A']=a[i][j+1]-'A';
     }
   }
   rep(i,m){
     for(int j=0;j<b[i].size()-1;j++){
       nextt[b[i][j]-'A']=b[i][j+1]-'A';
     }
   }

   if(n==m&& n==1){
     cout<<a[0]<<endl;
     return 0;
   }
   int temp=0;
   string ans="";
   string real_ans="";


   for(int k=0;k<26;k++){
     ans="";
     ans+='A'+k;
       for(int i=0;i<30;i++){
         if(nextt[ans[i]-'A']==-1)break;
         ans+=(nextt[ans[i]-'A']+'A');
      }
      if(ans.size()>real_ans.size()){
        real_ans=ans;
      }
  }
   if(real_ans.size()<len){
     cout<<-1<<endl;
     return 0;
   }
  cout<<real_ans<<endl;





}
0