This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 4005;
string s[N];
vector <int> v;
int dp[N],d[N],P[N];
ll go(ll a,ll b){
ll ans =1;
while(b){
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());
}
P[0] = 1;
for (int i = 1; i <= 2000; i++)
P[i] = (P[i - 1]*i)%mod;
sort(s+1,s+n+1);
int cnt=1;
for (int i=1; i<=n; i++){
if (s[i] != s[i + 1]) v.pb(cnt),cnt=0;
cnt++;
}
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 (stderr)
anagramistica.cpp:25:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main (){
| ^
anagramistica.cpp: In function 'int main()':
anagramistica.cpp:48: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]
48 | for(int i=0; i <v.size();i++){
| ~~^~~~~~~~~
anagramistica.cpp:46:8: warning: unused variable 'ans' [-Wunused-variable]
46 | ll ans=0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |