結果

問題 No.1688 Veterinarian
ユーザー chocoruskchocorusk
提出日時 2021-09-24 21:41:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 3,000 ms
コード長 2,460 bytes
コンパイル時間 3,334 ms
コンパイル使用メモリ 189,240 KB
実行使用メモリ 109,364 KB
最終ジャッジ日時 2023-09-18 20:59:53
合計ジャッジ時間 5,102 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,712 KB
testcase_01 AC 23 ms
102,168 KB
testcase_02 AC 7 ms
32,172 KB
testcase_03 AC 2 ms
7,576 KB
testcase_04 AC 2 ms
7,660 KB
testcase_05 AC 2 ms
7,768 KB
testcase_06 AC 22 ms
102,132 KB
testcase_07 AC 12 ms
11,616 KB
testcase_08 AC 385 ms
109,364 KB
testcase_09 AC 358 ms
108,216 KB
testcase_10 AC 45 ms
73,664 KB
testcase_11 AC 45 ms
53,164 KB
testcase_12 AC 6 ms
12,456 KB
testcase_13 AC 16 ms
61,076 KB
testcase_14 AC 10 ms
20,200 KB
testcase_15 AC 41 ms
102,008 KB
testcase_16 AC 7 ms
22,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
int a, b, c, n;
double dp[51][51][51][51];
double p[51][51][51][51];
int main()
{
    cin>>a>>b>>c>>n;
    for(int t=0; t<3; t++){
        for(int i=0; i<=n; i++){
            for(int j=0; j<=a; j++){
                for(int k=0; k<=b; k++){
                    for(int l=0; l<=c; l++){
                        dp[i][j][k][l]=0;
                        p[i][j][k][l]=0;
                    }
                }
            }
        }
        double ans=0;
        p[0][a][b][c]=1;
        for(int i=0; i<n; i++){
            for(int j=0; j<=a; j++){
                for(int k=0; k<=b; k++){
                    for(int l=0; l<=c; l++){
                        int x=(j+k+l)*(j+k+l-1);
                        if(x==0)continue;
                        int y=j*(j-1), z=k*(k-1), w=l*(l-1);
                        int u[3]={};u[t]++;
                        if(j) p[i+1][j-1][k][l]+=p[i][j][k][l]*y/x;
                        if(k) p[i+1][j][k-1][l]+=p[i][j][k][l]*z/x;
                        if(l) p[i+1][j][k][l-1]+=p[i][j][k][l]*w/x;
                        if(x) p[i+1][j][k][l]+=p[i][j][k][l]*(x-y-z-w)/x;
                        if(j) dp[i+1][j-1][k][l]+=(dp[i][j][k][l]*y/x+p[i][j][k][l]*y/x*u[0]);
                        if(k) dp[i+1][j][k-1][l]+=(dp[i][j][k][l]*z/x+p[i][j][k][l]*z/x*u[1]);
                        if(l) dp[i+1][j][k][l-1]+=(dp[i][j][k][l]*w/x+p[i][j][k][l]*w/x*u[2]);
                        if(x) dp[i+1][j][k][l]+=dp[i][j][k][l]*(x-y-z-w)/x;
                    }
                }
            }
        }
        for(int j=0; j<=a; j++){
            for(int k=0; k<=b; k++){
                for(int l=0; l<=c; l++){
                    ans+=dp[n][j][k][l];
                }
            }
        }
        printf("%.8lf", ans);
        if(t<2) cout<<" ";
        else cout<<endl;
    }
    return 0;
}
0