Submission #923806

# Submission time Handle Problem Language Result Execution time Memory
923806 2024-02-07T19:38:43 Z Isam Anagramistica (COCI21_anagramistica) C++17
10 / 110
6 ms 11612 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 = 1001, 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 = k; j >= 0; --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

anagramistica.cpp: In function 'int main()':
anagramistica.cpp:26:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |  for(register int i = 1; i <= n; ++i){
      |                   ^
anagramistica.cpp:33:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |  for(register int i = 2; i <= n; ++i){
      |                   ^
anagramistica.cpp:34:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |   for(register int j = 0; j <= i; ++j){
      |                    ^
anagramistica.cpp:41:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |  for(register int i = 1; i <= m; ++i){
      |                   ^
anagramistica.cpp:43:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |   for(register int j = k; j >= 0; --j){
      |                    ^
anagramistica.cpp:44:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |    for(register int l = 0; l <= ai && C[l][2] <= j; ++l){
      |                     ^
# 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 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 Runtime error 6 ms 11612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 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 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Runtime error 6 ms 11612 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -