結果

問題 No.1151 チャレンジゲーム
ユーザー snow39snow39
提出日時 2020-10-16 18:48:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 668 ms / 2,000 ms
コード長 1,811 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 105,156 KB
実行使用メモリ 10,968 KB
最終ジャッジ日時 2023-09-28 02:24:31
合計ジャッジ時間 21,144 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 159 ms
6,084 KB
testcase_14 AC 171 ms
5,952 KB
testcase_15 AC 163 ms
5,940 KB
testcase_16 AC 151 ms
6,048 KB
testcase_17 AC 162 ms
6,052 KB
testcase_18 AC 160 ms
5,888 KB
testcase_19 AC 153 ms
5,948 KB
testcase_20 AC 160 ms
5,944 KB
testcase_21 AC 162 ms
5,964 KB
testcase_22 AC 167 ms
6,052 KB
testcase_23 AC 165 ms
6,064 KB
testcase_24 AC 153 ms
6,052 KB
testcase_25 AC 166 ms
5,960 KB
testcase_26 AC 165 ms
5,888 KB
testcase_27 AC 160 ms
6,072 KB
testcase_28 AC 592 ms
10,936 KB
testcase_29 AC 649 ms
10,820 KB
testcase_30 AC 642 ms
10,804 KB
testcase_31 AC 613 ms
10,924 KB
testcase_32 AC 620 ms
10,900 KB
testcase_33 AC 644 ms
10,908 KB
testcase_34 AC 600 ms
10,936 KB
testcase_35 AC 648 ms
10,796 KB
testcase_36 AC 654 ms
10,920 KB
testcase_37 AC 644 ms
10,812 KB
testcase_38 AC 631 ms
10,808 KB
testcase_39 AC 632 ms
10,744 KB
testcase_40 AC 645 ms
10,912 KB
testcase_41 AC 634 ms
10,744 KB
testcase_42 AC 651 ms
10,900 KB
testcase_43 AC 653 ms
10,960 KB
testcase_44 AC 668 ms
10,800 KB
testcase_45 AC 598 ms
10,904 KB
testcase_46 AC 647 ms
10,944 KB
testcase_47 AC 624 ms
10,804 KB
testcase_48 AC 20 ms
4,756 KB
testcase_49 AC 631 ms
10,940 KB
testcase_50 AC 598 ms
10,968 KB
testcase_51 AC 653 ms
10,924 KB
testcase_52 AC 604 ms
10,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0