結果

問題 No.108 トリプルカードコンプ
ユーザー oxyshoweroxyshower
提出日時 2020-01-20 16:03:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,271 bytes
コンパイル時間 1,802 ms
コンパイル使用メモリ 175,812 KB
実行使用メモリ 11,752 KB
最終ジャッジ日時 2023-09-15 21:02:15
合計ジャッジ時間 3,272 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 15 ms
11,512 KB
testcase_08 AC 9 ms
11,564 KB
testcase_09 AC 9 ms
11,604 KB
testcase_10 AC 9 ms
11,492 KB
testcase_11 AC 10 ms
11,612 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 13 ms
10,788 KB
testcase_19 AC 10 ms
10,380 KB
testcase_20 AC 10 ms
11,580 KB
testcase_21 AC 12 ms
11,752 KB
testcase_22 AC 9 ms
10,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);

signed main(){

  int n; cin >> n;
  vector<int> a(n), cnt(4, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    cnt[min(3LL, a[i])]++;
  }

  auto dp = make_vec<double>(n+1, n+1, n+1);
  fill(dp, -1);
  dp[0][0][0] = 0;
  function< double(int,int,int) > rec =
  [&](int a, int b, int c){
    if(dp[a][b][c] != -1) return dp[a][b][c];
    double E = 1.0 * n / (a + b + c);
    if(a > 0) E += rec(a-1, b+1, c) * a / (a + b + c);
    if(b > 0) E += rec(a, b-1, c+1) * b / (a + b + c);
    if(c > 0) E += rec(a, b, c-1) * c / (a + b + c);
    return dp[a][b][c] = E;
  };
  printf("%.9f\n",rec(cnt[0], cnt[1], cnt[2]));

  return 0;
}
0