結果

問題 No.517 壊れたアクセサリー
ユーザー aaaaaaiu
提出日時 2019-08-28 11:35:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 967 bytes
コンパイル時間 2,001 ms
コンパイル使用メモリ 196,136 KB
最終ジャッジ日時 2025-01-07 15:26:49
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample TLE * 4
other TLE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin>>n;
    string s[n];
    int len=0;
    for (int i=0;i<n;i++) {
        cin>>s[i];
        len+=s[i].size();
    }
    int m;
    cin>>m;
    string t[m];
    for (int i=0;i<m;i++)
        cin>>t[i];
    for (int i=0;i<n;i++) {
        string a=s[i];
        string b="";
        while (a.size()!=b.size()) {
            if (a.size()<b.size())
                for (int j=0;j<n;j++)
                    if (s[j][0]==b[a.size()]) {
                        a+=s[j];
                        break;
                    }
            else if (a.size()>b.size())
                for (int j=0;j<m;j++)
                    if (t[j][0]==a[b.size()]){
                        b+=t[j];
                        break;
                    }
        }
        if (a.size()==len) {
            cout<<a<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}
0