我的代码WA3个点。
调了2天了,救救孩子吧!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void fastio(const char *infile, const char *outfile) {
if (infile) freopen(infile, "r", stdin);
if (outfile) freopen(outfile, "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int n, m;
string s[10];
string t[100010];
void solve(string now, int stp) {
now += s[stp];
if (stp == n) {
if (now.size() >= 3 && !binary_search(t + 1, t + 1 + m, now)) {
cout << now << endl;
exit(0);
}
} else for (int i = 1; now.size() + i + s[stp + 1].size() <= 16; i++) {
now += "_";
solve(now, stp + 1);
}
}
int main() {
fastio(nullptr, nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i];
for (int i = 1; i <= m; i++) cin >> t[i];
sort(s + 1, s + 1 + n);
sort(t + 1, t + 1 + m);
do solve("", 1);
while (next_permutation(s + 1, s + 1 + n));
cout << -1 << endl;
return 0;
}