結果

問題 No.517 壊れたアクセサリー
コンテスト
ユーザー WutongDeath
提出日時 2025-09-21 11:33:25
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,348 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 482 ms
コンパイル使用メモリ 97,444 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-15 04:29:37
合計ジャッジ時間 4,873 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n, m, cnt;
string ans;
vector<string> s1, s2;

int main() {
    // freopen("ring.in", "r", stdin);
    // freopen("ring.out", "w", stdout);
    
    scanf("%d", &n);
    s1.resize(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> s1[i];
    }
    scanf("%d", &m);
    s2.resize(m + 1);
    for (int i = 1; i <= m; ++i) {
        cin >> s2[i];
    }

    do {
        do {
            string str1, str2;
            for (int i = 0; i < s1.size(); ++i) {
                str1 += s1[i];
            }
            for (int i = 0; i < s2.size(); ++i) {
                str2 += s2[i];
            }

            bool ok = false;
            for (int i = 0; i < str1.size(); ++i) {
                if (str1[i] != str2[i]) break;
                if (i == str1.size() - 1)    {
                    if (ans != str1 || ans == "") {
                        ++cnt;
                        ok = true;
                    }
                }
            }
            if (cnt > 1) {
                puts("-1");
                return 0;
            }
            if (ok) {
                ans = str1;
            }
        } while (next_permutation(s2.begin(), s2.end()));
    } while (next_permutation(s1.begin(), s1.end()));

    cout << ans << endl;

    return 0;
}
0