Submission #512733

#TimeUsernameProblemLanguageResultExecution timeMemory
512733blueAnagramistica (COCI21_anagramistica)C++17
110 / 110
15 ms16712 KiB
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; const ll mod = 1'000'000'007; int ad(ll a, ll b) { return (a+b)%mod; } int mul(ll a, ll b) { return (a*b)%mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; string s[n]; vi val{0}; for(int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s, s+n); for(int i = 0; i < n; i++) { if(i == 0 || s[i] != s[i-1]) val.push_back(1); else val.back()++; } int ch[1+n][1+n]; for(int i = 0; i <= n; i++) { ch[i][0] = ch[i][i] = 1; for(int j = 1; j < i; j++) ch[i][j] = (ch[i-1][j] + ch[i-1][j-1]) % mod; } int z = int(val.size())-1; vvi dp(1+z, vi(1+k, 0)); dp[0][0] = 1; for(int i = 1; i <= z; i++) { for(int j = 0; j <= k; j++) { for(int c = 0; j - (c*(c-1)/2) >= 0 && c <= val[i]; c++) { dp[i][j] = ad(dp[i][j], mul(ch[val[i]][c], dp[i-1][j - (c*(c-1))/2])); } } } cout << dp[z][k] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...