結果

問題 No.174 カードゲーム(Hard)
ユーザー n_vipn_vip
提出日時 2015-03-27 01:11:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 751 ms / 2,000 ms
コード長 2,458 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 106,608 KB
実行使用メモリ 32,436 KB
最終ジャッジ日時 2023-09-21 02:43:30
合計ジャッジ時間 7,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 646 ms
32,340 KB
testcase_03 AC 751 ms
32,436 KB
testcase_04 AC 685 ms
32,372 KB
testcase_05 AC 651 ms
32,244 KB
testcase_06 AC 685 ms
32,248 KB
testcase_07 AC 667 ms
32,372 KB
testcase_08 AC 649 ms
32,376 KB
testcase_09 AC 669 ms
32,252 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

void findP(vector<int> &v,long double p,vv<long double> &re){
  int n=v.size(),m;
  queue<int> que;
  vector<int> usd(1<<n);
  vector<long double> prob(1<<n);
  que.push((1<<n)-1);
  prob[(1<<n)-1]=1;
  int st;
  while(!que.empty()){
    st=que.front(); que.pop();
    if(usd[st])continue;
    usd[st]=1;
    m=__builtin_popcount(st);
    int f=0;
    rep(i,n)if(st>>i&1){
      long double tmp;
      if(!f){
	tmp=prob[st]*(m==1?1:p);
	f=1;
      }else{
	tmp=prob[st]*(1-p)/(m-1);
      }
      prob[st^(1<<i)]+=tmp;
      re[i][n-m]+=tmp;
      que.push(st^(1<<i));
    }
  }
  //cout<<usd;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  int i,j,k,n;
  double pa,pb;
  cin>>n>>pa>>pb;
  vector<int> a(n),b(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  sort(all(a)); sort(all(b));
  //a[i]がj番目に使われる確率を求めたかったけど誤差がやばい
  vv<long double> odra(n,vector<long double>(n)),odrb(n,vector<long double>(n));
  findP(a,pa,odra); findP(b,pb,odrb);
  //cout<<odra<<odrb;
  //rep(i,n)cout<<accumulate(all(odra[i]),0.)<<",";cout<<endl;
  //rep(i,n)cout<<accumulate(all(odrb[i]),0.)<<",";cout<<endl;
  long double re=0,sum;
  rep(i,n)rep(j,n){
    if(a[i]<=b[j])continue;
    rep(k,n)
      re+=odra[i][k]*odrb[j][k]*(a[i]+b[j]);
  }
  cout<<(double)re<<endl;
  return 0;
}
0