結果
問題 | No.1151 チャレンジゲーム |
ユーザー |
![]() |
提出日時 | 2020-10-16 18:48:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 716 ms / 2,000 ms |
コード長 | 1,811 bytes |
コンパイル時間 | 1,224 ms |
コンパイル使用メモリ | 105,756 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-07-20 21:01:36 |
合計ジャッジ時間 | 22,153 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <iostream>#include <algorithm>#include <string>#include <vector>#include <cmath>#include <map>#include <queue>#include <iomanip>#include <set>#include <tuple>#define mkp make_pair#define mkt make_tuple#define rep(i,n) for(int i = 0; i < (n); ++i)#define all(v) v.begin(),v.end()using namespace std;typedef long long ll;const ll MOD=1e9+7;template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}int N;vector<int> A;typedef tuple<int,int,int> TP;map<TP,double> mp;double solve(int c,int state,int win){TP tmp=mkt(c,state,win);if(mp.count(tmp)) return mp[tmp];if(state==0){int s=0,t=0;rep(i,N){if(win&(1<<i)) s+=A[i];else t+=A[i];}if((c==0&&s>t)||(c==1&&s<=t)) return mp[tmp]=1;else return mp[tmp]=0;}double res=0;for(int a=0;a<N;a++){if((state&(1<<a))==0) continue;if(A[a]==1){int nw=win;if(c==0) nw^=(1<<a);chmax(res,(1-solve(1-c,state^(1<<a),nw)));continue;}double score=1;for(int b=0;b<N;b++){if((state&(1<<b))==0) continue;double coef=(A[a]*A[b])/(double)(A[a]+A[b]-1);double val=0;if(c==0){val+=coef*(1-solve(1-c,state^(1<<a),win^(1<<a)))/A[a];val+=coef*(solve(c,state^(1<<b),win))*((A[a]-1)/(double)A[a])/A[b];}else{val+=coef*(1-solve(1-c,state^(1<<a),win))/A[a];val+=coef*(solve(c,state^(1<<b),win^(1<<b)))*((A[a]-1)/(double)A[a])/A[b];}chmin(score,val);}chmax(res,score);}return mp[tmp]=res;}int main(){cin.tie(0);ios::sync_with_stdio(false);cin>>N;A.resize(N);rep(i,N) cin>>A[i];double ans=solve(0,(1<<N)-1,0);cout<<fixed<<setprecision(10)<<ans<<endl;return 0;}