結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
Bantako
|
| 提出日時 | 2018-06-09 21:14:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,451 bytes |
| コンパイル時間 | 1,823 ms |
| コンパイル使用メモリ | 176,856 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-30 13:02:02 |
| 合計ジャッジ時間 | 2,672 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
コンパイルメッセージ
main.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main(){
| ^~~~
ソースコード
#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;
}
Bantako