結果

問題 No.517 壊れたアクセサリー
ユーザー 梧桐
提出日時 2025-09-21 11:53:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,348 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 80,952 KB
実行使用メモリ 15,944 KB
最終ジャッジ日時 2025-09-21 11:53:52
合計ジャッジ時間 4,886 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 TLE * 1 -- * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #

#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