Submission #401079

# Submission time Handle Problem Language Result Execution time Memory
401079 2021-05-09T10:28:48 Z NintsiChkhaidze Anagramistica (COCI21_anagramistica) C++14
10 / 110
394 ms 676 KB
#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;
    }
    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 Correct 4 ms 428 KB Output is correct
2 Correct 5 ms 388 KB Output is correct
3 Correct 5 ms 388 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
5 Correct 6 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 394 ms 676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 428 KB Output is correct
2 Correct 5 ms 388 KB Output is correct
3 Correct 5 ms 388 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
5 Correct 6 ms 428 KB Output is correct
6 Runtime error 394 ms 676 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -