Submission #656447

#TimeUsernameProblemLanguageResultExecution timeMemory
656447thanh913Anagramistica (COCI21_anagramistica)C++14
110 / 110
5 ms6356 KiB
#include <bits/stdc++.h> using namespace std; //types #define ll long long #define ld long double #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second #define inf 0x3f3f3f3f #define pw2(x) (1LL << (x)) #define getBit(x, y) ((x) & (1LL << (y))) template<class X, class Y> bool cmax(X &a, const Y &b) { return a < b ? a = b, 1 : 0; } template<class X, class Y> bool cmin(X &a, const Y &b) { return a > b ? a = b, 1 : 0; } //lowercase 31, all 53 //(P/Q) % M = (P % M) * (Q^(M-2) % M) //------------------------------------------------------- const ld PI = 3.14159265359; const ll N = 2e3+5, mod = 1e9+7; ll n, m, x, a[N]; ll f2[N][N], f[N][N]; map<string, int> mp; ll add(ll &x, ll y) { if ((x += y) > mod) x -= mod; return x; } ll mu(ll x, ll y) { if (!y) return 1; ll tmp = mu(x, y/2); tmp = tmp * tmp % mod; if (y % 2) return tmp * x % mod; return tmp; } ll fac[N], inv[N]; ll ckn(ll k, ll n) { if (k > n) return 0; return (fac[n] * inv[k] % mod * inv[n-k] % mod); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); cin >> n >> x; for (int i = 1; i <= n; i++) { string tmp; cin >> tmp; sort(tmp.begin(), tmp.end()); mp[tmp]++; } for (auto u : mp) { a[++m] = u.se; } fac[0] = 1; for (int i = 1; i <= 2000; i++) { fac[i] = fac[i-1] * i % mod; } inv[2000] = mu(fac[2000], mod-2); for (int i = 1999; i >= 0; i--) { inv[i] = inv[i+1] * (i+1) % mod; } f[0][0] = 1; for (int i = 1; i <= m; i++) { for (int j = 0; j <= x; j++) f[i][j] = f[i-1][j]; for (int j = 1; j <= a[i]; j++) { ll cnt = j * (j-1) / 2, cnt2 = ckn(j, a[i]); for (int k = 0; k <= x - cnt; k++) { add(f[i][k+cnt], f[i-1][k] * cnt2 % mod); } } } cout << f[m][x]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...