Submission #923898

# Submission time Handle Problem Language Result Execution time Memory
923898 2024-02-08T05:14:08 Z Isam Anagramistica (COCI21_anagramistica) C++17
110 / 110
10 ms 31636 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;

constexpr int sz = 2002;
const int mod = 1e9 + 7;

int n, k;
long long dp[sz], C[sz][sz];
string s;
unordered_map<string, int> cnt;

int main(){
	speed;
	cin >> n >> k;
	for(register int i = 1; i <= n; ++i){
		cin >> s;
		sort(all(s));
		cnt[s]++;
	}
	C[1][0] = C[1][1] = 1;
	for(register int i = 2; i <= n; ++i){
		for(register int j = 0; j <= i; ++j){
			if(!j){
				C[i][0] = 1;
				continue;
			}
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
			C[i][j] %= mod;
		}
	}
	dp[0] = 1;
	for(auto &to : cnt){
		int ai = to.second;
		for(register int i = k; i >= 0; --i){
			for(register int take = 1; take <= ai && C[take][2] <= i; ++take){
				dp[i] += 1ll * dp[i - C[take][2]] * C[ai][take] % mod;
				dp[i] %= mod;
			}
		}
	}
	cout << dp[k] % mod << '\n';
	return 0;
}

Compilation message

anagramistica.cpp: In function 'int main()':
anagramistica.cpp:20:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   20 |  for(register int i = 1; i <= n; ++i){
      |                   ^
anagramistica.cpp:26:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |  for(register int i = 2; i <= n; ++i){
      |                   ^
anagramistica.cpp:27:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   27 |   for(register int j = 0; j <= i; ++j){
      |                    ^
anagramistica.cpp:39:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   39 |   for(register int i = k; i >= 0; --i){
      |                    ^
anagramistica.cpp:40:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |    for(register int take = 1; take <= ai && C[take][2] <= i; ++take){
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20828 KB Output is correct
2 Correct 6 ms 25180 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 7 ms 31580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 4 ms 20828 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 7 ms 31580 KB Output is correct
10 Correct 3 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
13 Correct 4 ms 16732 KB Output is correct
14 Correct 5 ms 25160 KB Output is correct
15 Correct 6 ms 24924 KB Output is correct
16 Correct 10 ms 31636 KB Output is correct
17 Correct 9 ms 31580 KB Output is correct
18 Correct 8 ms 31580 KB Output is correct