結果

問題 No.133 カードゲーム
ユーザー 山崎愛一山崎愛一
提出日時 2021-06-21 19:06:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 781 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 172,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 01:55:15
合計ジャッジ時間 3,287 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 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,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),c(1<<N);
  for(int i=0;i<N;i++)
    cin >> A[i];
  for(int i=0;i<N;i++)
    cin >> B[i];
  c[0]=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<(1<<i);j++)
      c[j+(1<<i)]=c[j]+1;
  vector<vector<double>> d(1<<N);
  d[0]={1};
  int l;
  for(int i=1;i<(1<<N);i++){
    d[i].assign(c[i]+1,0);
    for(int j=0;j<N;j++){
      if(i&(1<<j)){
        if(A[c[i]-1]>B[j]){
          l=1;
        } else {
          l=0;
        }
        for(int k=0;k<c[i];k++)
          d[i][k+l]+=d[i^(1<<j)][k];
      }
    }
    for(int j=0;j<=c[i];j++)
      d[i][j]/=c[i];
  }
  double ans=0;
  for(int i=N/2+1;i<=N;i++)
    ans+=d[(1<<N)-1][i];
  cout << fixed << setprecision(6) << ans << endl;
}
0