#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
#define int ll
#define sz(x) (int)x.size()
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<string> a(n);
for(auto &i : a){
cin >> i;
}
auto isAnagram = [&](string i, string j) -> bool {
vector<int> freq1(26), freq2(26);
for(char c : i){
freq1[c-'a']++;
}
for(char c : j){
freq2[c-'a']++;
}
for(int i=0; i<26; ++i){
if(freq1[i] != freq2[i]) return 0;
}
return 1;
};
int ans = 0;
for(int mask=0; mask<(1ll<<n); ++mask){
vector<string> tmp;
for(int j=0; j<n; ++j){
if(mask & (1ll << j)){
tmp.push_back(a[j]);
}
}
int cnt = 0;
for(int j=0; j<sz(tmp); ++j){
for(int k=j+1; k<sz(tmp); ++k){
if(isAnagram(tmp[j], tmp[k])) cnt++;
}
}
if(cnt == k){
ans++;
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
348 KB |
Output is correct |
4 |
Correct |
36 ms |
348 KB |
Output is correct |
5 |
Correct |
80 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
348 KB |
Output is correct |
4 |
Correct |
36 ms |
348 KB |
Output is correct |
5 |
Correct |
80 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
1074 ms |
352 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |