結果

問題 No.108 トリプルカードコンプ
ユーザー sirogamichan1sirogamichan1
提出日時 2020-11-23 19:41:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 3,205 bytes
コンパイル時間 5,799 ms
コンパイル使用メモリ 370,600 KB
実行使用メモリ 13,872 KB
最終ジャッジ日時 2023-10-01 00:00:17
合計ジャッジ時間 7,545 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,772 KB
testcase_01 AC 6 ms
13,700 KB
testcase_02 AC 5 ms
13,808 KB
testcase_03 AC 5 ms
13,844 KB
testcase_04 AC 6 ms
13,868 KB
testcase_05 AC 5 ms
13,836 KB
testcase_06 AC 5 ms
13,772 KB
testcase_07 AC 8 ms
13,872 KB
testcase_08 AC 6 ms
13,636 KB
testcase_09 AC 5 ms
13,840 KB
testcase_10 AC 5 ms
13,636 KB
testcase_11 AC 6 ms
13,716 KB
testcase_12 AC 5 ms
13,768 KB
testcase_13 AC 6 ms
13,868 KB
testcase_14 AC 5 ms
13,864 KB
testcase_15 AC 5 ms
13,720 KB
testcase_16 AC 6 ms
13,768 KB
testcase_17 AC 5 ms
13,872 KB
testcase_18 AC 8 ms
13,776 KB
testcase_19 AC 6 ms
13,848 KB
testcase_20 AC 6 ms
13,724 KB
testcase_21 AC 7 ms
13,864 KB
testcase_22 AC 5 ms
13,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//////////////////////////////
// Check before you submit.
// #define _ATCODER_LIBRARY

const long long MOD = 1e9+7;
// const long long MOD = 998244353;

/////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

#ifdef _ATCODER_LIBRARY
#include <atcoder/all>
using namespace atcoder;
#endif
// _ATCODER_LIBRARY

const long long INF = 1LL << 60;
const double PI = acos(-1);
using ll = long long;
using P = pair<ll, ll>;


#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SUM(v) accumulate(ALL(v),0ll)

template<typename T>istream& operator>>(istream&i,vector<T>&v){REP(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;REP(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";REP(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v){return o<<v.first<<","<<v.second;}

#define DEBUG(x);

#ifdef _DEBUG
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
#define GLIBCXX_DEBUG
#define GLIBCXX_DEBUG_PEDANTIC
#endif
// _DEBUG

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

void init_init_init() {ios_base::sync_with_stdio(false);cin.tie(NULL);std::cout<<fixed<<setprecision(10);}
template<class T>T up(T a, T b){assert(b);return (a+b-1)/b;}
template<typename... A>bool eq(A const&... a){auto t={a...};assert(t.size());auto tar=*t.begin();for(const auto&e:t)if(tar!=e)return false;return true;}

template<class T>bool chmin(T &a, T b){if(a>b){a=b;return false;}return true;}
template<class T>bool chmax(T &a, T b){if(a<b){a=b;return false;}return true;}
template<class T>bool chmax(T &a, initializer_list<T>l){return chmax(a,max(l));}
template<class T>bool chmin(T &a, initializer_list<T>l){return chmin(a,min(l));}

//////////////////////////////////////////////////////////////////
// My Library
//////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////
// Contest Code
//////////////////////////////////////////////////////////////////

double dp[110][110][110];
ll cnt[4];
ll N;

double solve(ll x, ll y, ll z)
{
	if (dp[x][y][z] != -1) return dp[x][y][z];
	ll d = N - x - y - z;
	double tmp = 1.f * N / (N-d);
	double res{tmp};
	if (x) res += (solve(x-1, y+1, z))*x/(x+y+z);
	if (y) res += (solve(x, y-1, z+1))*y/(x+y+z);
	if (z) res += (solve(x, y, z-1))*z/(x+y+z);
	return dp[x][y][z] = res;
}

int main(int argc, char **argv)
{
	init_init_init();

	REP(i, 105)REP(j, 105)REP(k, 105) dp[i][j][k] = -1;
	cin >> N;
	dp[0][0][0] = 0;
	REP(i, N)
	{
		ll a; cin >> a;
		cnt[min(3ll, a)]++;
	}
	std::cout << solve(cnt[0], cnt[1], cnt[2]) << std::endl;
}
0