# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
923809 | 2024-02-07T19:42:10 Z | Isam | Anagramistica (COCI21_anagramistica) | C++17 | 10 ms | 22620 KB |
#include<bits/stdc++.h> #define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define eb emplace_back #define all(x) x.begin(), x.end() using namespace std; const int sz = 2002, mod = 1e9 + 7; int n, k, cnt(1); int C[sz][sz]; string s; unordered_map<string, int> mp; unordered_map<int, int> a; long long dp[sz][sz]; int main(){ speed; cin >> n >> k; for(register int i = 1; i <= n; ++i){ cin >> s; sort(all(s)); if(!mp[s]) mp[s] = cnt++; a[mp[s]]++; } C[1][0] = C[1][1] = 1; for(register int i = 2; i <= n; ++i){ for(register int j = 0; j <= i; ++j){ C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod; } } int m = (int)a.size(); auto it = a.begin(); dp[0][0] = 1; for(register int i = 1; i <= m; ++i){ int ai = it->second; for(register int j = 0; j <= k; ++j){ for(register int l = 0; l <= ai && C[l][2] <= j; ++l){ dp[i][j] += 1ll * C[ai][l] * dp[i-1][j - C[l][2]] % mod; dp[i][j] %= mod; } } ++it; } cout << dp[m][k] << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2392 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 10844 KB | Output is correct |
2 | Correct | 4 ms | 13916 KB | Output is correct |
3 | Correct | 4 ms | 14940 KB | Output is correct |
4 | Correct | 7 ms | 17752 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 1 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2392 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 3 ms | 10844 KB | Output is correct |
7 | Correct | 4 ms | 13916 KB | Output is correct |
8 | Correct | 4 ms | 14940 KB | Output is correct |
9 | Correct | 7 ms | 17752 KB | Output is correct |
10 | Correct | 3 ms | 8284 KB | Output is correct |
11 | Correct | 1 ms | 6748 KB | Output is correct |
12 | Correct | 2 ms | 10844 KB | Output is correct |
13 | Correct | 3 ms | 10844 KB | Output is correct |
14 | Correct | 4 ms | 13660 KB | Output is correct |
15 | Correct | 4 ms | 12888 KB | Output is correct |
16 | Correct | 10 ms | 22620 KB | Output is correct |
17 | Correct | 8 ms | 16732 KB | Output is correct |
18 | Correct | 7 ms | 17500 KB | Output is correct |