結果

問題 No.108 トリプルカードコンプ
ユーザー tsutajtsutaj
提出日時 2018-02-19 03:22:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,973 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 99,364 KB
実行使用メモリ 13,864 KB
最終ジャッジ日時 2023-09-19 08:45:23
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 10 ms
13,604 KB
testcase_08 AC 5 ms
13,708 KB
testcase_09 AC 5 ms
13,788 KB
testcase_10 AC 6 ms
13,684 KB
testcase_11 AC 5 ms
13,612 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
8,636 KB
testcase_14 AC 4 ms
8,672 KB
testcase_15 AC 4 ms
8,496 KB
testcase_16 AC 4 ms
8,788 KB
testcase_17 AC 3 ms
8,496 KB
testcase_18 AC 9 ms
13,540 KB
testcase_19 AC 6 ms
13,688 KB
testcase_20 AC 6 ms
13,688 KB
testcase_21 AC 7 ms
13,864 KB
testcase_22 AC 6 ms
13,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N;
double dp[110][110][110];
int cnt[4];

double solve(int x, int y, int z) {
    // メモ化しよう
    if(dp[x][y][z] != -1) return dp[x][y][z];
    dp[x][y][z] = 0;
    // 2 枚以下しか持っていないものが出るまで引く回数の期待値
    double exp_num = 1.0 * N / (N - z);
    // (先の期待値) * (それを引く確率) の足しあわせ
    if(x != N) dp[x][y][z] += (solve(x+1, y, z) + exp_num) * (N - x) / (N - z);
    if(y != x) dp[x][y][z] += (solve(x, y+1, z) + exp_num) * (x - y) / (N - z);
    if(z != y) dp[x][y][z] += (solve(x, y, z+1) + exp_num) * (y - z) / (N - z);
    return dp[x][y][z];
}
 
signed main() {
    cin >> N;
    repq(i,0,N) repq(j,0,N) repq(k,0,N) dp[i][j][k] = -1;
    dp[N][N][N] = 0;

    rep(i,0,N) {
        int A; cin >> A;
        cnt[min(A, 3LL)]++;
    }
    repr(i,2,0) {
        cnt[i] += cnt[i+1];
    }

    printf("%.12f\n", solve(cnt[1], cnt[2], cnt[3]));
    return 0;
}
0