結果

問題 No.108 トリプルカードコンプ
ユーザー beetbeet
提出日時 2018-12-03 17:26:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 2,688 ms
コンパイル使用メモリ 202,472 KB
実行使用メモリ 14,344 KB
最終ジャッジ日時 2023-09-13 21:13:31
合計ジャッジ時間 4,375 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,304 KB
testcase_01 AC 5 ms
14,156 KB
testcase_02 AC 5 ms
14,120 KB
testcase_03 AC 5 ms
14,172 KB
testcase_04 AC 5 ms
14,124 KB
testcase_05 AC 6 ms
14,292 KB
testcase_06 AC 5 ms
14,288 KB
testcase_07 AC 10 ms
14,240 KB
testcase_08 AC 6 ms
14,280 KB
testcase_09 AC 6 ms
14,280 KB
testcase_10 AC 6 ms
14,172 KB
testcase_11 AC 6 ms
14,296 KB
testcase_12 AC 6 ms
14,156 KB
testcase_13 AC 6 ms
14,216 KB
testcase_14 AC 6 ms
14,128 KB
testcase_15 AC 6 ms
14,264 KB
testcase_16 AC 6 ms
14,160 KB
testcase_17 AC 6 ms
14,160 KB
testcase_18 AC 9 ms
14,324 KB
testcase_19 AC 7 ms
14,280 KB
testcase_20 AC 6 ms
14,168 KB
testcase_21 AC 8 ms
14,280 KB
testcase_22 AC 6 ms
14,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
double dp[111][111][111];
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  for(Int i=0;i<111;i++)
    for(Int j=0;j<111;j++)
      for(Int k=0;k<111;k++)
        dp[i][j][k]=-1;
  function<double(Int, Int, Int)> dfs=
    [&](Int x,Int y,Int z)->double{
      double &res=dp[x][y][z];
      if(res>=0) return res;
      if(x==0&&y==0&&z==0) return res=0;
      res=1;
      if(x) res+=dfs(x-1,y+1,z)*x/n;
      if(y) res+=dfs(x,y-1,z+1)*y/n;
      if(z) res+=dfs(x,y,z-1)*z/n;
      res*=1.0*n/(x+y+z);
      return res;
    };
  Int x=0,y=0,z=0;
  for(Int i=0;i<n;i++){
    if(a[i]==0) x++;
    if(a[i]==1) y++;
    if(a[i]==2) z++;
  }
  cout<<dfs(x,y,z)<<endl;
  return 0;
}
0