Submission #679802

#TimeUsernameProblemLanguageResultExecution timeMemory
679802faribourzAnagramistica (COCI21_anagramistica)C++14
110 / 110
11 ms6336 KiB
// Only GOD // believe in yourself // Nemidam Del Be In Darde Donya! #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef long double ld; typedef pair<int, int> pii; #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #define bit(x, y) ((x >> y)&1) #define sz(x) (int)x.size() #define kill(x) return cout << x << '\n', void() #define KILL(x) return cout << x << '\n', 0 const int N = 2e3+10; const int MOD = 1e9+7; int dp[N][N], inv[N], fac[N]; map<int, int> cnt; int a[N]; int mul(int a, int b){ a %= MOD, b %= MOD; return (a*b)%MOD; } int C(int n, int k){ if(k > n) return 0; return mul(mul(fac[n], inv[n-k]), inv[k]); } int pw2(int a, int b){ int res = 1; while(b){ if(b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } int hasher(string s){ int res = 0; int pw = 1; for(int i = 0; i < sz(s); i++){ res += (s[i]-'a'+1)*pw; pw *= 27; } return res; } int f(int x){ return (x*(x-1))/2; } int32_t main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n, k; cin >> n >> k; fac[0] = 1; for(int i = 1;i <= n; i++) fac[i] = mul(fac[i-1], i); for(int i = 0; i <= n; i++) inv[i] = pw2(fac[i], MOD-2); for (int i = 0;i < n; i++){ string s; cin >> s; sort(all(s)); cnt[hasher(s)]++; } int all = 1; for(auto u : cnt){ a[all++] = u.S; } dp[0][0] = 1; int ans = 0; for(int i = 1; i < all; i++){ for(int j=0; j <= k; j++){ for(int t = 0; t <= a[i]; t++){ int X = f(t); if(j - X < 0) continue; dp[i][j] = (mul(C(a[i], t) , dp[i-1][j-X]) + dp[i][j]) % MOD; } } } cout << dp[all-1][k]; }

Compilation message (stderr)

anagramistica.cpp: In function 'int32_t main()':
anagramistica.cpp:79:6: warning: unused variable 'ans' [-Wunused-variable]
   79 |  int ans = 0;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...