結果

問題 No.1151 チャレンジゲーム
ユーザー nikkukunnikkukun
提出日時 2020-08-13 18:23:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 169,044 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 01:46:15
合計ジャッジ時間 6,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 39 ms
6,940 KB
testcase_14 AC 39 ms
6,944 KB
testcase_15 AC 38 ms
6,940 KB
testcase_16 AC 39 ms
6,940 KB
testcase_17 AC 39 ms
6,940 KB
testcase_18 AC 40 ms
6,940 KB
testcase_19 AC 39 ms
6,944 KB
testcase_20 AC 38 ms
6,944 KB
testcase_21 AC 38 ms
6,940 KB
testcase_22 AC 41 ms
6,940 KB
testcase_23 AC 39 ms
6,940 KB
testcase_24 AC 39 ms
6,940 KB
testcase_25 AC 38 ms
6,940 KB
testcase_26 AC 38 ms
6,944 KB
testcase_27 AC 39 ms
6,940 KB
testcase_28 AC 136 ms
6,944 KB
testcase_29 AC 133 ms
6,944 KB
testcase_30 AC 132 ms
6,940 KB
testcase_31 AC 134 ms
6,940 KB
testcase_32 AC 132 ms
6,940 KB
testcase_33 AC 133 ms
6,940 KB
testcase_34 AC 133 ms
6,940 KB
testcase_35 AC 133 ms
6,940 KB
testcase_36 AC 137 ms
6,944 KB
testcase_37 AC 134 ms
6,944 KB
testcase_38 AC 133 ms
6,940 KB
testcase_39 AC 135 ms
6,944 KB
testcase_40 AC 133 ms
6,944 KB
testcase_41 AC 135 ms
6,940 KB
testcase_42 AC 132 ms
6,944 KB
testcase_43 AC 134 ms
6,944 KB
testcase_44 AC 131 ms
6,940 KB
testcase_45 AC 131 ms
6,944 KB
testcase_46 AC 131 ms
6,940 KB
testcase_47 AC 128 ms
6,940 KB
testcase_48 AC 131 ms
6,944 KB
testcase_49 AC 130 ms
6,940 KB
testcase_50 AC 131 ms
6,940 KB
testcase_51 AC 135 ms
6,940 KB
testcase_52 AC 131 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 10 + 2;
const int S = (59049) + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

double f[S][2];
bool vst[S][2];
int a[N];
int n;

double DFS(int s, int op) {
	if (vst[s][op]) return f[s][op];
	vst[s][op] = 1;
	vector<int> vec, pos;
	for (int i = 0, x = s; i < n; i++) {
		vec.push_back(x % 3);
		if (x % 3 == 0) pos.push_back(i);
		x /= 3;
	}
	if (pos.empty()) {
		int sum1 = 0, sum2 = 0;
		for (int i = 0; i < n; i++) {
			if (vec[i] == 1) sum1 += a[i];
			if (vec[i] == 2) sum2 += a[i];
		}
		if (op == 0) f[s][op] = sum1 > sum2;
		if (op == 1) f[s][op] = sum2 >= sum1;
	} else {
		for (auto i: pos) {
			double minf = 1;
			for (auto j: pos) {
				// get p(i, j)
				int s1 = s + pow(3, i) * (op + 1);
				int s2 = s + pow(3, j) * ((op ^ 1) + 1);
				double pij = (1.0 / a[i]) * (1 - DFS(s1, op ^ 1)) + (1 - 1.0 / a[i]) * (1.0 / a[j]) * DFS(s2, op);
				pij /= 1 - (1 - 1.0 / a[i]) * (1 - 1.0 / a[j]);
				minf = min(minf, pij);
			}
			f[s][op] = max(f[s][op], minf);
		}
	}
	return f[s][op];
}

int main() {
	ios::sync_with_stdio(0);

	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << fixed << setprecision(10) << DFS(0, 0) << endl;

	return 0;
}
0