結果

問題 No.1151 チャレンジゲーム
ユーザー leaf_1415leaf_1415
提出日時 2020-08-07 23:02:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 842 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 80,940 KB
実行使用メモリ 10,164 KB
最終ジャッジ日時 2023-10-25 04:12:20
合計ジャッジ時間 28,514 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 8 ms
4,348 KB
testcase_02 AC 17 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 9 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 16 ms
4,348 KB
testcase_13 AC 357 ms
8,452 KB
testcase_14 AC 359 ms
8,452 KB
testcase_15 AC 358 ms
8,452 KB
testcase_16 AC 359 ms
8,452 KB
testcase_17 AC 357 ms
8,452 KB
testcase_18 AC 357 ms
8,452 KB
testcase_19 AC 362 ms
8,452 KB
testcase_20 AC 362 ms
8,452 KB
testcase_21 AC 358 ms
8,452 KB
testcase_22 AC 364 ms
8,452 KB
testcase_23 AC 360 ms
8,452 KB
testcase_24 AC 353 ms
8,452 KB
testcase_25 AC 362 ms
8,452 KB
testcase_26 AC 362 ms
8,452 KB
testcase_27 AC 356 ms
8,452 KB
testcase_28 AC 787 ms
10,164 KB
testcase_29 AC 767 ms
10,164 KB
testcase_30 AC 778 ms
10,164 KB
testcase_31 AC 774 ms
10,164 KB
testcase_32 AC 781 ms
10,164 KB
testcase_33 AC 773 ms
10,164 KB
testcase_34 AC 792 ms
10,164 KB
testcase_35 AC 771 ms
10,164 KB
testcase_36 AC 773 ms
10,164 KB
testcase_37 AC 780 ms
10,164 KB
testcase_38 AC 791 ms
10,164 KB
testcase_39 AC 785 ms
10,164 KB
testcase_40 AC 781 ms
10,164 KB
testcase_41 AC 778 ms
10,164 KB
testcase_42 AC 779 ms
10,164 KB
testcase_43 AC 785 ms
10,164 KB
testcase_44 AC 792 ms
10,164 KB
testcase_45 AC 770 ms
10,164 KB
testcase_46 AC 780 ms
10,164 KB
testcase_47 AC 781 ms
10,164 KB
testcase_48 AC 842 ms
10,164 KB
testcase_49 AC 767 ms
10,164 KB
testcase_50 AC 813 ms
10,164 KB
testcase_51 AC 796 ms
10,164 KB
testcase_52 AC 780 ms
10,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[15];
double dp[1<<10][405][2];
llint zero = 202;

double calc(llint mask, llint pt, double x)
{
	double ret = 0;
	for(int i = 0; i < n; i++){
		if(mask & (1<<i)) continue;
		double p = 1.0/a[i];
		ret = max(ret, p*dp[mask|(1<<i)][zero+pt+a[i]][1] + (1-p)*x);
	}
	//cout << mask << " " << pt << " " << x << " " << ret << endl;
	return ret;
}

double calc2(llint mask, llint pt, double x)
{
	double ret = 1;
	for(int i = 0; i < n; i++){
		if(mask & (1<<i)) continue;
		double p = 1.0/a[i];
		ret = min(ret, p*dp[mask|(1<<i)][zero+pt-a[i]][0] + (1-p)*x);
	}
	return ret;
}

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	llint N = 1<<n;
	for(int j = 1; j <= 200; j++) dp[N-1][zero+j][0] = dp[N-1][zero+j][1] = 1;
	for(int i = N-2; i >= 0; i--){
		for(int j = -200; j <= 200; j++){
			llint mx = 0;
			for(int k = 0; k < n; k++){
				if((i & (1<<k)) == 0) mx = max(mx, a[k]);
			}
			if(abs(j) + mx > 200) continue;
		
			double ub = 1, lb = 0, mid;
			for(int k = 0; k < 50; k++){
				mid = (ub+lb)/2;
				if(calc2(i, j, calc(i, j, mid)) > mid) lb = mid;
				else ub = mid;
			}
			
			dp[i][zero+j][0] = calc(i, j, ub), dp[i][zero+j][1] = ub;
		}
	}
	/*for(int i = 0; i < N; i++){
		for(int j = -3; j <= 3; j++) cout << dp[i][zero+j][0] << " ";
		cout << endl;
	}*/
	printf("%.11f\n", dp[0][zero+0][0]);
	
	return 0;
}
0