結果

問題 No.517 壊れたアクセサリー
コンテスト
ユーザー Naoyk1212
提出日時 2017-05-28 22:15:41
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,151 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,075 ms
コンパイル使用メモリ 184,760 KB
実行使用メモリ 12,020 KB
最終ジャッジ日時 2026-04-09 20:51:56
合計ジャッジ時間 5,018 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int n;
	cin >> n;
	vector<string> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];

	int m;
	cin >> m;
	vector<string> b(m);
	for(int i = 0; i < m; i++)cin >> b[i];

	vector<string> str, str1;

	vector<int> tmp(n), tmp1(m);

	for(int i = 0; i < n; i++)tmp[i] = i;
	for(int i = 0; i < m; i++)tmp1[i] = i;
	string s;

	do{
		s = "";
		bool ok = false;
		for(int i = 0; i < n; i++)s += a[tmp[i]];
		for(int i = 0; i < str.size(); i++){
			if(str[i] == s)ok = true;
		}
		//cout << s << endl;
		if(!ok)str.push_back(s);

	}while(next_permutation(tmp.begin(), tmp.end()));

	do{
		s = "";
		bool ok = false;
		for(int i = 0; i < m; i++)s += b[tmp1[i]];
		for(int i = 0; i < str1.size(); i++){
			if(str1[i] == s)ok = true;
		}
		//cout << s << endl;
		if(!ok)str1.push_back(s);

	}while(next_permutation(tmp1.begin(), tmp1.end()));

	int count = 0;
	string ans;
	for(int i = 0; i < str.size(); i++){
		for(int j = 0; j < str1.size(); j++){
			if(str[i] == str1[j]){
				count++;
				ans = str[i];
			}
		}
	}
	
	if(count == 1)cout << ans << endl;
	else cout << -1 << endl;

}
0