Submission #942520

#TimeUsernameProblemLanguageResultExecution timeMemory
942520vjudge1Anagramistica (COCI21_anagramistica)C++17
10 / 110
1074 ms352 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...