結果

問題 No.108 トリプルカードコンプ
ユーザー pitsu_kyo_propitsu_kyo_pro
提出日時 2019-12-21 17:05:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,467 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 166,472 KB
実行使用メモリ 13,796 KB
最終ジャッジ日時 2023-09-27 01:33:00
合計ジャッジ時間 2,843 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 9 ms
13,796 KB
testcase_08 AC 5 ms
13,772 KB
testcase_09 AC 5 ms
13,664 KB
testcase_10 AC 5 ms
13,768 KB
testcase_11 AC 5 ms
13,640 KB
testcase_12 AC 2 ms
4,388 KB
testcase_13 AC 3 ms
8,692 KB
testcase_14 AC 3 ms
8,476 KB
testcase_15 AC 4 ms
8,688 KB
testcase_16 AC 3 ms
8,556 KB
testcase_17 AC 3 ms
8,512 KB
testcase_18 AC 8 ms
13,704 KB
testcase_19 AC 6 ms
13,544 KB
testcase_20 AC 6 ms
13,580 KB
testcase_21 AC 7 ms
13,648 KB
testcase_22 AC 5 ms
13,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;
double dp[110][110][110];
vector<int> cnt(4,0);

double rec(int x, int y, int z){
  if(dp[x][y][z] != -1) return dp[x][y][z];
  dp[x][y][z] = 0;
  double exp = 1.0*N/(N-z);
  if(x != N) dp[x][y][z] += (rec(x+1,y,z) + exp)*(N-x)/(N-z);
  if(y != x) dp[x][y][z] += (rec(x,y+1,z) + exp)*(x-y)/(N-z);
  if(z != y) dp[x][y][z] += (rec(x,y,z+1) + exp)*(y-z)/(N-z);
  return dp[x][y][z];
}

int main(){
  cin >> N;
  for(int i=0; i<=N; i++){
    for(int j=0; j<=N; j++){
      for(int k=0; k<=N; k++){
        dp[i][j][k] = -1;
      }
    }
  }
  dp[N][N][N] = 0;
 for(int i=0; i<N; i++){
    int a;
    cin >> a;
    cnt[min(a,3)]++;
  }
  cnt[2] += cnt[3];
  cnt[1] += cnt[2];
  cout << fixed << setprecision(10) << rec(cnt[1],cnt[2],cnt[3]) << endl;
  return 0;
}
0