#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define ll long long
#define int long long
using namespace std;
const int N = 2005;
string s[N];
map <string,int> cnt;
vector <int> v;
int dp[N],d[N],P[N];
ll go(ll a,ll b){
ll ans =1;
while(b > 0){
if (b&1) ans = (ans * a)%mod;
a = (a*a)%mod;
b/=2;
}
return ans;
}
ll C(int m,int n){
ll x = P[n],y = P[m],z = P[n - m];
y = (y*z)%mod;
return (x * go(y, mod - 2))%mod;;
}
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,k;
cin>>n>>k;
for (int i=1;i<=n;i++){
cin>>s[i];
sort(s[i].begin(),s[i].end());
cnt[s[i]]++;
}
P[0] = 1;
for (int i = 1; i <= 2000; i++)
P[i] = (P[i - 1]*i)%mod;
sort(s+1,s+n+1);
v.pb(cnt[s[1]]);
for (int i=2; i<=n; i++)
if (s[i] != s[i - 1]) v.pb(cnt[s[i]]);
ll ans=0;
dp[0] = 1;
for(int i=0; i <v.size();i++){
for (int m = 1; m <= v[i]; m++){
for (int j = 0; j <= 2000; j++){
ll x = (m*(m - 1))/2;
d[j + x] = (dp[j]*C(m,v[i]) + d[j + x])%mod;
}
}
for (int j=0;j<=2000;j++)
dp[j] = (dp[j] + d[j])%mod,d[j]=0;
}
if (k == 0) cout<<(dp[k] - 1 + mod)%mod;
else cout<<dp[k];
}
Compilation message
anagramistica.cpp:27:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main (){
| ^
anagramistica.cpp: In function 'int main()':
anagramistica.cpp:49:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0; i <v.size();i++){
| ~~^~~~~~~~~
anagramistica.cpp:47:8: warning: unused variable 'ans' [-Wunused-variable]
47 | ll ans=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
395 ms |
664 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |