This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |