提出 #65458298


ソースコード 拡げる

// #include <bits/allocator.h> // Temp fix for gcc13 global pragma
// #pragma GCC target("avx2,bmi2,popcnt,lzcnt")
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
#ifdef LOCAL
	#include "Debug.h"
#else
	#define debug_endl() 42
	#define debug(...) 42
	#define debug2(...) 42
	#define debug_bin(...) 42
#endif

// Enumerate all partitions of 0 to n in lexicographical order.
vector<vector<vector<int>>> enumerate_partitions(int n){
	assert(0 <= n);
	vector<vector<vector<int>>> p(n + 1);
	p[0] = {{}};
	for(auto x = 1; x <= n; ++ x) for(auto last = x; last >= 1; -- last) for(auto q: p[x - last]){
		if(!q.empty() && q.back() < last) break;
		q.push_back(last);
		p[x].push_back(q);
	}
	for(auto x = 1; x <= n; ++ x){
		reverse(p[x].begin(), p[x].end());
		for(auto &q: p[x]) reverse(q.begin(), q.end());
	}
	return p;
}
// Enumerate all partitions of 0 to n in lexicographical order, along with its occurence as set of sizes of cycles in S_n.
template<class T, bool PRECOMPUTE_INVERSE = false>
vector<vector<pair<vector<int>, T>>> enumerate_partitions_with_count(int n){
	auto p = enumerate_partitions(n);
	vector<T> fact(n + 1, 1), invfact, inv;
	for(auto x = 1; x <= n; ++ x) fact[x] = fact[x - 1] * x;
	if constexpr(PRECOMPUTE_INVERSE){
		invfact.resize(n + 1), inv.resize(n + 1, 1);
		invfact[n] = 1 / fact[n];
		for(auto x = n - 1; x >= 1; -- x){
			invfact[x] = invfact[x + 1] * (x + 1);
			inv[x + 1] = invfact[x + 1] * fact[x];
		}
	}
	vector<vector<pair<vector<int>, T>>> res(n + 1);
	for(auto x = 0; x <= n; ++ x){
		for(auto q: p[x]){
			T cnt = fact[x];
			for(auto y: q){
				if constexpr(PRECOMPUTE_INVERSE) cnt *= inv[y];
				else cnt /= y;
			}
			for(auto l = 0; l < (int)q.size(); ){
				int r = l;
				while(r < (int)q.size() && q[l] == q[r]) ++ r;
				if constexpr(PRECOMPUTE_INVERSE) cnt *= invfact[r - l];
				else cnt /= fact[r - l];
				l = r;
			}
			res[x].push_back({q, cnt});
		}
	}
	return res;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	cout << fixed << setprecision(15);
	int n, t, m, k;
	cin >> n >> t >> m >> k;
	vector<vector<int>> parts;
	for(auto all = enumerate_partitions(m)[m]; auto part: all){
		if((int)part.size() <= n){
			vector<int> cnt(m + 1);
			for(auto x: part){
				++ cnt[x];
			}
			cnt[0] = n - (int)part.size();
			parts.push_back(cnt);
		}
	}
	vector<double> dp(k + 1), dp_next(k + 1);
	dp[k] = 1;
	for(auto i = 0; i < t; ++ i){
		ranges::fill(dp_next, 0);
		dp_next[k] = 1;
		for(auto x = 0; x < k; ++ x){
			for(auto cnt: parts){
				double cur = 0;
				for(auto y = 0; y <= m; ++ y){
					cur += cnt[y] * dp[min(k, x + y)];
				}
				dp_next[x] = max(dp_next[x], cur / n);
			}
		}
		swap(dp, dp_next);
	}
	cout << dp[0] << "\n";
	return 0;
}

/*

*/

提出情報

提出日時
問題 F - Lost and Pound
ユーザ FlowerOfSorrow
言語 C++ 23 (gcc 12.2)
得点 550
コード長 2992 Byte
結果 AC
実行時間 211 ms
メモリ 6012 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 550 / 550
結果
AC × 3
AC × 54
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, random_45.txt, random_46.txt, random_47.txt, random_48.txt, random_49.txt, random_50.txt, random_51.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 1 ms 3740 KiB
random_02.txt AC 1 ms 3756 KiB
random_03.txt AC 41 ms 4424 KiB
random_04.txt AC 74 ms 5016 KiB
random_05.txt AC 89 ms 5320 KiB
random_06.txt AC 1 ms 3760 KiB
random_07.txt AC 3 ms 3980 KiB
random_08.txt AC 9 ms 3984 KiB
random_09.txt AC 1 ms 3740 KiB
random_10.txt AC 15 ms 4044 KiB
random_11.txt AC 1 ms 3648 KiB
random_12.txt AC 3 ms 3988 KiB
random_13.txt AC 5 ms 4060 KiB
random_14.txt AC 2 ms 4052 KiB
random_15.txt AC 1 ms 3732 KiB
random_16.txt AC 3 ms 4164 KiB
random_17.txt AC 1 ms 3616 KiB
random_18.txt AC 4 ms 3936 KiB
random_19.txt AC 1 ms 3644 KiB
random_20.txt AC 1 ms 3804 KiB
random_21.txt AC 1 ms 3740 KiB
random_22.txt AC 1 ms 3756 KiB
random_23.txt AC 1 ms 3624 KiB
random_24.txt AC 12 ms 4912 KiB
random_25.txt AC 10 ms 3888 KiB
random_26.txt AC 1 ms 3528 KiB
random_27.txt AC 3 ms 3856 KiB
random_28.txt AC 1 ms 3796 KiB
random_29.txt AC 3 ms 3924 KiB
random_30.txt AC 1 ms 3672 KiB
random_31.txt AC 4 ms 3884 KiB
random_32.txt AC 1 ms 3744 KiB
random_33.txt AC 211 ms 5736 KiB
random_34.txt AC 4 ms 6012 KiB
random_35.txt AC 12 ms 5612 KiB
random_36.txt AC 4 ms 5752 KiB
random_37.txt AC 1 ms 3744 KiB
random_38.txt AC 1 ms 3736 KiB
random_39.txt AC 1 ms 3736 KiB
random_40.txt AC 1 ms 3596 KiB
random_41.txt AC 12 ms 5592 KiB
random_42.txt AC 4 ms 5908 KiB
random_43.txt AC 6 ms 5644 KiB
random_44.txt AC 4 ms 5892 KiB
random_45.txt AC 1 ms 3756 KiB
random_46.txt AC 1 ms 3748 KiB
random_47.txt AC 1 ms 3744 KiB
random_48.txt AC 1 ms 3752 KiB
random_49.txt AC 29 ms 5008 KiB
random_50.txt AC 1 ms 3764 KiB
random_51.txt AC 2 ms 4384 KiB
sample_01.txt AC 1 ms 3684 KiB
sample_02.txt AC 1 ms 3740 KiB
sample_03.txt AC 1 ms 3624 KiB