結果

問題 No.517 壊れたアクセサリー
ユーザー Naoyk1212
提出日時 2017-05-28 22:15:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,151 bytes
コンパイル時間 1,369 ms
コンパイル使用メモリ 166,500 KB
実行使用メモリ 10,960 KB
最終ジャッジ日時 2024-09-21 15:32:45
合計ジャッジ時間 4,920 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#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