結果
問題 | No.108 トリプルカードコンプ |
ユーザー |
|
提出日時 | 2023-06-15 00:42:37 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 1,405 bytes |
コンパイル時間 | 3,765 ms |
コンパイル使用メモリ | 275,320 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-06-23 05:19:54 |
合計ジャッジ時間 | 4,731 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef LOCAL#include "debug.hpp"#else#define debug(...) 1#endifint n;vector<int> a;vector<vector<vector<bool>>> seen;vector<vector<vector<double>>> memo;double solve(int c1, int c2, int c3) {if (seen[c1][c2][c3]) {return memo[c1][c2][c3];}seen[c1][c2][c3] = true;if (c1 == 0 && c2 == 0 && c3 == 0) {return 0.0;}double ret = 1;if (c1 >= 1) {ret += solve(c1 - 1, c2, c3) * (double) c1 / n;}if (c2 >= 1) {ret += solve(c1 + 1, c2 - 1, c3) * (double) c2 / n;}if (c3 >= 1) {ret += solve(c1, c2 + 1, c3 - 1) * (double) c3 / n;}if (n - (c1 + c2 + c3) >= 1) {ret *= (double) n / (c1 + c2 + c3);}return memo[c1][c2][c3] = ret;}int main() {ios::sync_with_stdio(false);cin.tie(nullptr);cin >> n;a.resize(n);for (int i = 0; i < n; i++) {cin >> a[i];}seen.resize(n + 1, vector<vector<bool>>(n + 1, vector<bool>(n + 1, false)));memo.resize(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, 0)));int c1 = 0, c2 = 0, c3 = 0;for (int i = 0; i < n; i++) {int x = max(0, 3 - a[i]);if (x == 1) c1++;if (x == 2) c2++;if (x == 3) c3++;}double ans = solve(c1, c2, c3);cout << fixed << setprecision(15) << ans << '\n';}