提出 #4908554


ソースコード 拡げる

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

//O(r)で愚直にnCrを計算、最悪O(N)
double nCr(double n, int r) {
	double mul = n;
	double div = (double)r;
	double ret = 1.0;
	for (int i = 0; i < r; i++) {
		ret *= mul;
		ret /= div;
		mul -= 1.0;
		div -= 1.0;
	}
	return ret;
}

double fact(int n) {
	double ret = 1.0;
	double mul = (double)n;
	for (int i = 0; i < n; i++) {
		ret *= mul;
		mul -= 1.0;
	}
	return ret;
}

//meani[i][j] := i番目のコインがj(0-indexed)にあってそれが表になる確率
double meani[101][101];
int divisor[101];

signed main() {

	int N, C[101];
	fact(5);

	cin >> N;
	rep(i, N) {
		cin >> C[i];
	}
	//O(N^2)で約数の個数を数える
	rep(i, N) {
		rep(j, N) {
			if (i == j) continue;
			if (C[i] % C[j] == 0) {
				divisor[i]++;
			}
		}
	}

	//meaniを求める
	rep(i, N) {
		rep(j, N) {
			if (divisor[i] == 0) {
				meani[i][j] = fact(N-1) / fact(N);
				continue;
			}
			//一番左にある場合は必ず表
			if (j == 0) {
				meani[i][j] = fact(N-1) / fact(N);
				continue;
			}

			for (int numDiv = 0; numDiv <= min(j , divisor[i]); numDiv += 2) {
				bool cond;
				int notDiviser = N - divisor[i] - 1;
				//jの左に置く約数の個数が足りている、かつjの左に置く約数でない数の個数が足りていることが必要
				cond = (numDiv <= divisor[i] && notDiviser >= j - numDiv);

				if (cond) {
					//divisor[i]: i番目の数の約数の個数
					//notDiviser: i番目の数の約数でない数の個数

					//置く約数の選び方
					double divChoice = nCr(divisor[i], numDiv);

					//jの左のどこに約数を置くか
					double posLeft = nCr((double)j, numDiv);
					//約数の並べ方
					double factDivLeft = fact(numDiv);
					//jの右のどこに約数をおくか
					double posRight = nCr(N - j - 1, divisor[i] - numDiv);
					//約数の並べ方
					double factDivRight = fact(divisor[i] - numDiv);

					meani[i][j] +=divChoice * posLeft * factDivLeft * posRight * factDivRight * fact(notDiviser);
				}
				
			}
			meani[i][j] /= fact(N);
		}
	}
	
	double ans = 0.0;
	rep(i, N)rep(j, N) ans += meani[i][j];
	cout << fixed;
	cout << setprecision(8) << ans << endl;

	return 0;
}

提出情報

提出日時
問題 C - コイン
ユーザ ymduu
言語 C++14 (GCC 5.4.1)
得点 100
コード長 4108 Byte
結果 AC
実行時間 64 ms
メモリ 384 KB

ジャッジ結果

セット名 Sample Subtask1 Subtask2
得点 / 配点 0 / 0 99 / 99 1 / 1
結果
AC × 3
AC × 20
AC × 40
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt
Subtask2 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 1 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt AC 1 ms 256 KB
subtask1_10.txt AC 1 ms 256 KB
subtask1_11.txt AC 1 ms 256 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 256 KB
subtask1_14.txt AC 1 ms 256 KB
subtask1_15.txt AC 1 ms 256 KB
subtask1_16.txt AC 1 ms 256 KB
subtask1_17.txt AC 1 ms 256 KB
subtask1_18.txt AC 1 ms 256 KB
subtask1_19.txt AC 1 ms 256 KB
subtask1_20.txt AC 1 ms 256 KB
subtask2_01.txt AC 1 ms 256 KB
subtask2_02.txt AC 1 ms 256 KB
subtask2_03.txt AC 1 ms 256 KB
subtask2_04.txt AC 5 ms 384 KB
subtask2_05.txt AC 7 ms 384 KB
subtask2_06.txt AC 3 ms 384 KB
subtask2_07.txt AC 2 ms 384 KB
subtask2_08.txt AC 64 ms 384 KB
subtask2_09.txt AC 63 ms 384 KB
subtask2_10.txt AC 60 ms 384 KB
subtask2_11.txt AC 47 ms 384 KB
subtask2_12.txt AC 46 ms 384 KB
subtask2_13.txt AC 7 ms 384 KB
subtask2_14.txt AC 47 ms 384 KB
subtask2_15.txt AC 43 ms 384 KB
subtask2_16.txt AC 4 ms 384 KB
subtask2_17.txt AC 61 ms 384 KB
subtask2_18.txt AC 2 ms 384 KB
subtask2_19.txt AC 4 ms 384 KB
subtask2_20.txt AC 64 ms 384 KB