結果

問題 No.174 カードゲーム(Hard)
ユーザー 0w10w1
提出日時 2017-01-04 17:07:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 2,185 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 166,440 KB
実行使用メモリ 20,052 KB
最終ジャッジ日時 2023-09-21 03:00:12
合計ジャッジ時間 4,846 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,592 KB
testcase_01 AC 2 ms
5,704 KB
testcase_02 AC 329 ms
20,052 KB
testcase_03 AC 324 ms
20,036 KB
testcase_04 AC 329 ms
19,920 KB
testcase_05 AC 330 ms
19,928 KB
testcase_06 AC 330 ms
20,040 KB
testcase_07 AC 329 ms
19,988 KB
testcase_08 AC 325 ms
20,048 KB
testcase_09 AC 325 ms
20,040 KB
testcase_10 AC 2 ms
5,716 KB
testcase_11 AC 2 ms
5,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

const int MAXN = 20;

int N;
double Pa, Pb;
int A[ MAXN ];
int B[ MAXN ];

void init(){
  cin >> N;
  cin >> Pa >> Pb;
  for( int i = 0; i < N; ++i ){
    cin >> A[ i ];
  }
  for( int i = 0; i < N; ++i ){
    cin >> B[ i ];
  }
}

double dp_a[ 1 << MAXN ];
double dp_b[ 1 << MAXN ];
double turn_id_a[ MAXN + 1 ][ MAXN + 1 ];
double turn_id_b[ MAXN + 1 ][ MAXN + 1 ];

void build_dp( int a[], double p, double dp[], double turn_id[][ MAXN + 1 ] ){
  dp[ 0 ] = 1.0;
  for( int s = 0; s < 1 << N; ++s ){
    int turn = __builtin_popcount( s );
    int n = N - turn;
    int minv = INF;
    for( int i = 0; i < N; ++i ){
      if( ~s & 1 << i ){
        upmin( minv, a[ i ] );
      }
    }
    for( int i = 0; i < N; ++i ){
      if( ~s & 1 << i ){
        if( a[ i ] == minv ){
          dp[ s | 1 << i ] += dp[ s ] * ( n == 1 ? 1.0 : p );
          turn_id[ turn ][ i ] += dp[ s ] * ( n == 1 ? 1.0 : p );
        } else{
          dp[ s | 1 << i ] += dp[ s ] * ( 1.0 - p ) / ( n - 1 );
          turn_id[ turn ][ i ] += dp[ s ] * ( 1.0 - p ) / ( n - 1 );
        }
      }
    }
  }
}

void preprocess(){
  build_dp( A, Pa, dp_a, turn_id_a );
  build_dp( B, Pb, dp_b, turn_id_b );
}

void solve(){
  double ans = 0.0;
  for( int i = 0; i < N; ++i ){
    for( int j = 0; j < N; ++j ){
      for( int k = 0; k < N; ++k ){
        if( A[ j ] <= B[ k ] ) continue;
        ans += turn_id_a[ i ][ j ] * turn_id_b[ i ][ k ] * ( A[ j ] + B[ k ] );
      }
    }
  }
  cout << fixed << setprecision( 10 ) << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0