結果

問題 No.1688 Veterinarian
ユーザー koutykkkkoutykkk
提出日時 2021-09-25 11:32:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 354 ms / 3,000 ms
コード長 3,297 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 202,216 KB
実行使用メモリ 75,224 KB
最終ジャッジ日時 2023-09-18 22:58:53
合計ジャッジ時間 4,525 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
75,140 KB
testcase_01 AC 19 ms
75,148 KB
testcase_02 AC 20 ms
75,224 KB
testcase_03 AC 22 ms
74,968 KB
testcase_04 AC 20 ms
75,024 KB
testcase_05 AC 20 ms
75,024 KB
testcase_06 AC 21 ms
75,024 KB
testcase_07 AC 30 ms
75,168 KB
testcase_08 AC 354 ms
75,132 KB
testcase_09 AC 325 ms
75,144 KB
testcase_10 AC 45 ms
75,168 KB
testcase_11 AC 53 ms
75,024 KB
testcase_12 AC 22 ms
75,132 KB
testcase_13 AC 23 ms
75,140 KB
testcase_14 AC 24 ms
75,180 KB
testcase_15 AC 38 ms
75,044 KB
testcase_16 AC 21 ms
75,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const int INF = ((1<<30)-1);
const ll LINF = (1LL<<60);
const double PI = 3.141592653589793238;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
double dp[55][55][55][55];

double Com(int n,int k){
    double res = 1;
    rep(i,0,k){
        res *= (n-i);
        res /= (k-i);
    }
    return res;
}

signed main(){
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0), cin.tie(0);
    int a,b,c,n; cin >> a >> b >> c >> n;
    rep(i,0,55)rep(j,0,55)rep(k,0,55)rep(l,0,55)dp[i][j][k][l] = 0;
    dp[0][a][b][c] = 1;
    rep(i,0,n){
        rep(j,0,a+1){
            rep(k,0,b+1){
                rep(l,0,c+1){
                    rep(ch1,0,3){
                        rep(ch2,ch1,3){
                            if(ch1 == 0 || ch2 == 0){
                                if(ch2 == ch1 && j < 2)continue;
                                if(j < 1)continue;
                            }
                            if(ch1 == 1 || ch2 == 1){
                                if(ch2 == ch1 && k < 2)continue;
                                if(k < 1)continue;
                            }
                            if(ch1 == 2 || ch2 == 2){
                                if(ch2 == ch1 && l < 2)continue;
                                if(l < 1)continue;
                            }
                            double c1 = j;
                            if(ch1 == 1)c1 = k;
                            if(ch1 == 2)c1 = l;
                            double c2 = j;
                            if(ch2 == 1)c2 = k;
                            if(ch2 == 2)c2 = l;
                            if(ch1 == ch2)c2 -= 1;
                            double tmp = c1 * c2;
                            if(ch1 == ch2)tmp /= 2;
                            double kakuritu =  tmp / Com(j+k+l , 2);
                            if(ch1 == ch2){
                                if(ch1 == 0)dp[i+1][j-1][k][l] += kakuritu * dp[i][j][k][l];
                                if(ch1 == 1)dp[i+1][j][k-1][l] += kakuritu * dp[i][j][k][l];
                                if(ch1 == 2)dp[i+1][j][k][l-1] += kakuritu * dp[i][j][k][l];
                            }
                            else{
                                dp[i+1][j][k][l] += kakuritu * dp[i][j][k][l];
                            }
                        }
                    }
                }
            }
        }
    }
    double ansa = 0, ansb = 0, ansc = 0;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                ansa += dp[n][i][j][k] * (a-i);
                ansb += dp[n][i][j][k] * (b-j);
                ansc += dp[n][i][j][k] * (c-k);
            }
        }
    }
    cout << ansa << " " << ansb << " " << ansc << endl;

	return 0;
}
0