#include<bits/stdc++.h>
using namespace std;
int n, m;
string a[55];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
int mn = 1e9;
map<string, int> cnt;
for(int mask = 0; mask < (1 << n); ++mask) {
vector<string> b, c;
for(int i = 0; i < n; ++i) {
if(mask >> i & 1) {
b.push_back(a[i+1]);
}
}
sort(b.begin(), b.end());
do {
string cur;
for(auto x : b) {
cur += x;
}
c.push_back(cur);
} while(next_permutation(b.begin(), b.end()));
for(auto x : c) {
if(cnt.count(x)) {
mn = min(mn, (int)x.size());
}
}
for(auto x : c) {
cnt[x]++;
}
}
if(mn == 1e9) {
cout << "-1";
return 0;
}
cout << mn;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
114 ms |
46184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |