답안 #679800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679800 2023-01-09T08:54:32 Z faribourz Anagramistica (COCI21_anagramistica) C++14
0 / 110
1 ms 596 KB
// Only GOD
// believe in yourself
// Nemidam Del Be In Darde Donya!
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define int ll
typedef long double ld;
typedef pair<int, int> pii;
 
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define bit(x, y) ((x >> y)&1)
#define sz(x) (int)x.size()
#define kill(x) return cout << x << '\n', void()
#define KILL(x) return cout << x << '\n', 0
 
const int N = 2e3+10;
const int MOD = 1e9+7;
int dp[N][N], inv[N], fac[N];
map<int, int> cnt;
int a[N];
int mul(int a, int b){
	a %= MOD, b %= MOD;
	return (a*b)%MOD;
}
int C(int n, int k){
	if(k > n)
		return 0;
	return mul(mul(fac[n], inv[n-k]), inv[k]);
}
int pw2(int a, int b){
	int res = 1;
	while(b){
		if(b & 1)
			res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
int hasher(string s){
	int res = 0;
	int pw = 1;
	for(int i = 0; i < sz(s); i++){
		res += (s[i]-'a'+1)*pw;
		pw *= 27;
	}
	return res;
}
int f(int x){
	return (x*(x-1))/2;
}
int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k;
	fac[0] = 1;
	for(int i = 1;i <= n; i++)
		fac[i] = mul(fac[i-1], i);
	for(int i = 0; i <= n; i++)
		inv[i] = pw2(fac[i], MOD-2);
	for (int i = 0;i < n; i++){
		string s;
		cin >> s;
		sort(all(s));
		cnt[hasher(s)]++;
	}
	int all = 1;
	for(auto u : cnt){
		a[all++] = u.S;
	}
	dp[0][0] = 1;
	int ans = 0;
	for(int i = 1; i < all; i++){
		for(int j=0; j <= k; j++){
			for(int t = 0; t <= a[i]; t++){
				int X = f(t);	
				dp[i][j] = (mul(C(a[i], t) , dp[i-1][j-X]) + dp[i][j]) % MOD;
			}
		}
		ans = (ans + dp[i][k])%MOD;
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -