Submission #397611

# Submission time Handle Problem Language Result Execution time Memory
397611 2021-05-02T14:21:42 Z MrRobot_28 Anagramistica (COCI21_anagramistica) C++17
110 / 110
31 ms 35140 KB
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define int long long
#define sz(a) (int)a.size()
const int mod = 1e9 + 7;
const int N = 2e3 + 100;
int cnk[N][N];
signed main()
{
  //  ifstream cin("input1.txt.4c");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            cnk[i][j] = 0;
        }
    }
    cnk[0][0] = 1;
    for(int i = 1; i < N; i++)
    {
        cnk[i][0] = 1;
        for(int j = 1; j < N; j++)
        {
            cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % mod;
        }
    }
    int n, k;
    cin >> n >> k;
    map<vector <int>, int> mp;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        vector <int> cnt(26, 0);
        for(int j = 0; j < sz(s); j++)
        {
            cnt[s[j] - 'a']++;
        }
        mp[cnt]++;
    }
    vector <int> dp(k + 1, 0);
    dp[0] = 1;
    for(auto p : mp)
    {
        int t = p.Y;
        for(int j = k; j >= 0; j--)
        {
            for(int f = t; f >= 1; f--)
            {
                int add = f * (f - 1) / 2;
             //   cout << dp[j] << " " << add << " " << cnk[t][f] << "\n";
                if(add + j <= k)
                {
                    dp[add + j] = (dp[add + j] + dp[j] * cnk[t][f]) % mod;
                }
            }
        }
     //   cout << dp[k] << "\n";
    }
    cout << dp[k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 34764 KB Output is correct
2 Correct 28 ms 34800 KB Output is correct
3 Correct 28 ms 34836 KB Output is correct
4 Correct 28 ms 34836 KB Output is correct
5 Correct 27 ms 34784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 34836 KB Output is correct
2 Correct 28 ms 34832 KB Output is correct
3 Correct 28 ms 34832 KB Output is correct
4 Correct 28 ms 34836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 34764 KB Output is correct
2 Correct 28 ms 34800 KB Output is correct
3 Correct 28 ms 34836 KB Output is correct
4 Correct 28 ms 34836 KB Output is correct
5 Correct 27 ms 34784 KB Output is correct
6 Correct 28 ms 34836 KB Output is correct
7 Correct 28 ms 34832 KB Output is correct
8 Correct 28 ms 34832 KB Output is correct
9 Correct 28 ms 34836 KB Output is correct
10 Correct 29 ms 34824 KB Output is correct
11 Correct 28 ms 34764 KB Output is correct
12 Correct 28 ms 34764 KB Output is correct
13 Correct 28 ms 34796 KB Output is correct
14 Correct 29 ms 34832 KB Output is correct
15 Correct 28 ms 34832 KB Output is correct
16 Correct 30 ms 35140 KB Output is correct
17 Correct 31 ms 34764 KB Output is correct
18 Correct 28 ms 34884 KB Output is correct