結果

問題 No.517 壊れたアクセサリー
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-28 11:35:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 967 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 199,920 KB
実行使用メモリ 12,244 KB
最終ジャッジ日時 2023-08-11 03:35:17
合計ジャッジ時間 8,250 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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