답안 #923807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923807 2024-02-07T19:39:21 Z Isam Anagramistica (COCI21_anagramistica) C++17
110 / 110
10 ms 22600 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 = 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){
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11000 KB Output is correct
2 Correct 4 ms 13916 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 6 ms 17756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 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 3 ms 11000 KB Output is correct
7 Correct 4 ms 13916 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 6 ms 17756 KB Output is correct
10 Correct 3 ms 8148 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 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 12892 KB Output is correct
16 Correct 10 ms 22600 KB Output is correct
17 Correct 8 ms 16732 KB Output is correct
18 Correct 6 ms 17436 KB Output is correct