結果

問題 No.1151 チャレンジゲーム
ユーザー chocoruskchocorusk
提出日時 2020-08-07 22:48:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,804 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 128,544 KB
実行使用メモリ 20,124 KB
最終ジャッジ日時 2023-10-25 03:40:57
合計ジャッジ時間 4,475 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,800 KB
testcase_01 AC 2 ms
5,848 KB
testcase_02 AC 2 ms
5,912 KB
testcase_03 AC 2 ms
5,792 KB
testcase_04 AC 3 ms
5,792 KB
testcase_05 AC 2 ms
5,800 KB
testcase_06 AC 2 ms
5,800 KB
testcase_07 AC 2 ms
5,816 KB
testcase_08 AC 2 ms
5,816 KB
testcase_09 AC 2 ms
5,848 KB
testcase_10 AC 2 ms
5,848 KB
testcase_11 AC 2 ms
5,912 KB
testcase_12 AC 2 ms
5,912 KB
testcase_13 AC 11 ms
14,648 KB
testcase_14 AC 11 ms
14,648 KB
testcase_15 AC 11 ms
14,648 KB
testcase_16 AC 12 ms
14,648 KB
testcase_17 AC 11 ms
14,648 KB
testcase_18 AC 11 ms
14,648 KB
testcase_19 AC 12 ms
14,648 KB
testcase_20 AC 11 ms
14,648 KB
testcase_21 AC 10 ms
14,648 KB
testcase_22 AC 11 ms
14,648 KB
testcase_23 AC 11 ms
14,648 KB
testcase_24 AC 11 ms
14,648 KB
testcase_25 AC 10 ms
14,648 KB
testcase_26 AC 11 ms
14,648 KB
testcase_27 AC 11 ms
14,648 KB
testcase_28 AC 32 ms
20,124 KB
testcase_29 AC 33 ms
20,124 KB
testcase_30 AC 33 ms
20,124 KB
testcase_31 AC 32 ms
20,124 KB
testcase_32 AC 33 ms
20,124 KB
testcase_33 AC 33 ms
20,124 KB
testcase_34 AC 34 ms
20,124 KB
testcase_35 AC 33 ms
20,124 KB
testcase_36 AC 32 ms
20,124 KB
testcase_37 AC 31 ms
20,124 KB
testcase_38 AC 31 ms
20,124 KB
testcase_39 AC 31 ms
20,124 KB
testcase_40 AC 30 ms
20,124 KB
testcase_41 AC 31 ms
20,124 KB
testcase_42 AC 31 ms
20,124 KB
testcase_43 AC 31 ms
20,124 KB
testcase_44 AC 31 ms
20,124 KB
testcase_45 AC 31 ms
20,124 KB
testcase_46 AC 31 ms
20,124 KB
testcase_47 AC 31 ms
20,124 KB
testcase_48 AC 31 ms
20,124 KB
testcase_49 AC 32 ms
20,124 KB
testcase_50 AC 32 ms
20,124 KB
testcase_51 AC 31 ms
20,124 KB
testcase_52 AC 31 ms
20,124 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>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
double dp[2][1<<10][1<<10];
int n;
int a[20];
double solve(int t, int x, int y){
	if(dp[t][x][y]>-0.5){
		return dp[t][x][y];
	}
	if((x^y)==((1<<n)-1)){
		int sx=0, sy=0;
		for(int i=0; i<n; i++){
			if(x&(1<<i)) sx+=a[i];
			else sy+=a[i];
		}
		if(sx>=sy) return dp[t][x][y]=0;
		else return dp[t][x][y]=1;
	}
	if(t==0){
		double mn=1;
		for(int i=0; i<n; i++){
			if(x&(1<<i) || y&(1<<i)) continue;
			double p=1.0/a[i];
			double mx=0;
			for(int j=0; j<n; j++){
				if(x&(1<<j) || y&(1<<j)) continue;
				double q=1.0/a[j];
				mx=max(mx, p/(1-(1-p)*(1-q))*solve(1, x^(1<<i), y)+(1-p)*q/(1-(1-p)*(1-q))*solve(0, x, y^(1<<j)));
			}
			mn=min(mn, mx);
		}
		return dp[t][x][y]=mn;
	}else{
		double mx=0;
		for(int i=0; i<n; i++){
			if(x&(1<<i) || y&(1<<i)) continue;
			double p=1.0/a[i];
			double mn=1;
			for(int j=0; j<n; j++){
				if(x&(1<<j) || y&(1<<j)) continue;
				double q=1.0/a[j];
				mn=min(mn, q*(1-p)/(1-(1-p)*(1-q))*solve(1, x^(1<<j), y)+p/(1-(1-p)*(1-q))*solve(0, x, y^(1<<i)));
			}
			mx=max(mn, mx);
		}
		return dp[t][x][y]=mx;
	}
}
int main()
{
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<(1<<n); i++){
		for(int j=0; j<(1<<n); j++){
			dp[0][i][j]=dp[1][i][j]=-1;
		}
	}
	printf("%.7lf\n", solve(1, 0, 0));
	return 0;
}
0