結果

問題 No.108 トリプルカードコンプ
ユーザー tsutajtsutaj
提出日時 2018-01-25 11:15:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,751 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 99,292 KB
実行使用メモリ 13,876 KB
最終ジャッジ日時 2023-08-27 05:48:17
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 9 ms
13,756 KB
testcase_08 AC 5 ms
13,876 KB
testcase_09 AC 5 ms
13,760 KB
testcase_10 AC 6 ms
13,600 KB
testcase_11 AC 6 ms
13,620 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
8,680 KB
testcase_14 AC 3 ms
8,508 KB
testcase_15 AC 3 ms
8,736 KB
testcase_16 AC 3 ms
8,536 KB
testcase_17 AC 3 ms
8,656 KB
testcase_18 AC 8 ms
13,556 KB
testcase_19 AC 6 ms
13,512 KB
testcase_20 AC 6 ms
13,580 KB
testcase_21 AC 7 ms
13,800 KB
testcase_22 AC 5 ms
13,716 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] = 1;
    if(x != N) dp[x][y][z] += 1.0 * solve(x+1, y, z) * (N - x) / N;
    if(y != x) dp[x][y][z] += 1.0 * solve(x, y+1, z) * (x - y) / N;
    if(z != y) dp[x][y][z] += 1.0 * solve(x, y, z+1) * (y - z) / N;
    dp[x][y][z] *= 1.0 * N / (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