Submission #386874

# Submission time Handle Problem Language Result Execution time Memory
386874 2021-04-07T14:40:22 Z phathnv Anagramistica (COCI21_anagramistica) C++11
110 / 110
19 ms 19436 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 2007;
const int MOD = 1e9 + 7;

int n, k, numWord, c[N];
int nCk[N][N], dp[N][N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;
    map<string, int> cnt;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        cnt[s]++;
    }
    for(auto p : cnt)
        c[++numWord] = p.second;

    for(int i = 0; i <= n; i++){
        nCk[i][0] = 1;
        for(int j = 1; j <= i; j++)
            nCk[i][j] = (nCk[i - 1][j] + nCk[i - 1][j - 1]) % MOD;
    }
    dp[0][0] = 1;
    for(int i = 0; i < numWord; i++)
        for(int j = 0; j <= k; j++)
            for(int x = 0; x <= c[i + 1]; x++){
                int nxtJ = j + x * (x - 1) / 2;
                if (nxtJ <= k)
                    dp[i + 1][nxtJ] = (dp[i + 1][nxtJ] + (ll) dp[i][j] * nCk[c[i + 1]][x] % MOD) % MOD;
            }
    cout << dp[numWord][k];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8556 KB Output is correct
2 Correct 9 ms 11628 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 12 ms 15468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 6 ms 8556 KB Output is correct
7 Correct 9 ms 11628 KB Output is correct
8 Correct 10 ms 12396 KB Output is correct
9 Correct 12 ms 15468 KB Output is correct
10 Correct 5 ms 4972 KB Output is correct
11 Correct 3 ms 3564 KB Output is correct
12 Correct 5 ms 6636 KB Output is correct
13 Correct 6 ms 6508 KB Output is correct
14 Correct 10 ms 11136 KB Output is correct
15 Correct 8 ms 10348 KB Output is correct
16 Correct 19 ms 19436 KB Output is correct
17 Correct 16 ms 14444 KB Output is correct
18 Correct 13 ms 15212 KB Output is correct