結果

問題 No.517 壊れたアクセサリー
ユーザー BantakoBantako
提出日時 2018-06-09 21:14:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,451 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 172,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 02:23:10
合計ジャッジ時間 3,386 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:22:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   22 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
string cat(string s,string t){
    if(s.find(t) != -1)return s;
    if(t.find(s) != -1)return t;
    rep(i,0,s.size()){
        if(s[i] == t[0]){
            return s.substr(0,i) + t;
        }
    }
    rep(i,0,t.size()){
        if(s[0] == t[i]){
            return t.substr(0,i) + s;
        }
    }
    return "";
}
main(){
    int N,M;
    set<string> st;
    cin >> N;
    rep(i,0,N){
        string s;
        cin >> s;
        st.insert(s);
    }
    cin >> M;
    rep(i,0,M){
        string s;
        cin >> s;
        st.insert(s);
    }
    bool flag = 1;
    while(st.size() != 1 && flag){
        flag = 0;
        next:
        for(auto S = st.begin();S != st.end();S++)
        for(auto T = st.begin();T != st.end();T++){
            //cout << *S << " " << *T << endl;
            if(S == T)continue;
            string str = cat(*S,*T);
            //cout << "str:" << str << endl;
            if(str != ""){
                flag = 1;
                st.erase(S);
                st.erase(T);                
                st.insert(str);
                //cout << "hogeee" << endl;
                goto next;
            }
        }
        //cout << st.size() << endl;
    }
    if(st.size() == 1)cout << *st.begin() << endl;
    else              cout << -1 << endl;
}
0