結果

問題 No.108 トリプルカードコンプ
ユーザー たこしたこし
提出日時 2019-10-03 22:24:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,653 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 199,444 KB
実行使用メモリ 12,756 KB
最終ジャッジ日時 2023-07-26 20:12:44
合計ジャッジ時間 2,933 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,664 KB
testcase_01 AC 5 ms
12,756 KB
testcase_02 AC 4 ms
12,524 KB
testcase_03 AC 5 ms
12,608 KB
testcase_04 AC 4 ms
12,572 KB
testcase_05 AC 5 ms
12,532 KB
testcase_06 AC 5 ms
12,520 KB
testcase_07 AC 9 ms
12,504 KB
testcase_08 AC 5 ms
12,672 KB
testcase_09 AC 5 ms
12,500 KB
testcase_10 AC 5 ms
12,756 KB
testcase_11 AC 4 ms
12,688 KB
testcase_12 AC 5 ms
12,756 KB
testcase_13 AC 5 ms
12,496 KB
testcase_14 AC 5 ms
12,500 KB
testcase_15 AC 6 ms
12,712 KB
testcase_16 AC 6 ms
12,640 KB
testcase_17 AC 5 ms
12,524 KB
testcase_18 AC 8 ms
12,748 KB
testcase_19 AC 6 ms
12,488 KB
testcase_20 AC 5 ms
12,628 KB
testcase_21 AC 7 ms
12,612 KB
testcase_22 AC 5 ms
12,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 105;
int N;
int A[MAX_N];
int sumA[3];

double dp[MAX_N][MAX_N][MAX_N];

double solve(int i, int j, int k) {
  if(i == 0 && j == 0 && k == 0) {
    return 0.0;
  }

  if(dp[i][j][k] >= 0) {
    return dp[i][j][k];
  }

  double ret = N;

  if(i-1 >= 0) {
    ret += solve(i-1,j+1,k) * (i);
  }
  if(j-1 >= 0) {
    ret += solve(i,j-1,k+1) * (j);
  }
  if(k-1 >= 0) {
    ret += solve(i,j,k-1) * (k);
  }

  return dp[i][j][k] = ret / (i+j+k);
}

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> A[n];
    if(A[n] >= 3) {
      continue;
    } else {
      sumA[A[n]]++;
    }
  }

  REP(i,MAX_N) {
    REP(j,MAX_N) {
      REP(k,MAX_N) {
        dp[i][j][k] = -1.0;
      }
    }
  }

  printf("%.15f\n", solve(sumA[0],sumA[1],sumA[2]));

  return 0;
}
0