結果
| 問題 | No.133 カードゲーム | 
| コンテスト | |
| ユーザー |  mamumamura1 | 
| 提出日時 | 2019-02-23 12:11:13 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 2,148 bytes | 
| コンパイル時間 | 1,811 ms | 
| コンパイル使用メモリ | 174,936 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-29 12:06:58 | 
| 合計ジャッジ時間 | 2,904 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 19 | 
ソースコード
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
vi A,B;
ll n;
double win=0;
double sum=0;
ll cnt=0;
ll ho[1000][1000];
void dfs2(int depth,ll bit,vi hog){
  //cout<<bit<<endl;
  if(depth == n){
    //cout<<"!"<<endl;
    for(int i=0;i<hog.size();i++)ho[cnt][i]=hog[i];
    cnt++;
    return;
  }
  for(int i=0;i<n;i++){
    //cout<<(bit|(BITLE(i)))<<" "<<(bit&BITLE(i))<<endl;
    if(!(bit&BITLE(i))){
      //cout<<(bit|BITLE(i))<<endl;
      hog.pb(B[i]);
      dfs2(depth+1,bit|BITLE(i),hog);
      hog.pop_back();
    }
  }
}
void dfs(ll depth,ll bit,vi hog){
  if(depth == n){
    //cout<<"!"<<endl;
    vi h;
    //for(auto a:hog)cout<<a<<" ";
    //cout<<endl;
    for(int j=0;j<300;j++){
      if(ho[j][0]==0)return;
    double wincn=0;
    double draw=0;
    double lose=0;
      for(int i=0;i<n;i++){
	//cout<<hog[i]<<" "<<ho[j][i]<<endl;
	if(hog[i] > ho[j][i])wincn+=1;
	else if(hog[i] == ho[j][i])draw+=1;
	else lose+=1;
      }
      if(wincn>lose)win+=1;
      sum+=1;
    }
    return;
  }
  for(int i=0;i<n;i++){
    if(!(bit&BITLE(i))){
      //  cout<<(bit|BITLE(i))<<endl;
      hog.pb(A[i]);
      dfs(depth+1,bit|BITLE(i),hog);
      hog.pop_back();
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  A.resize(n);
  B.resize(n);
  for(auto &a:A)cin>>a;
  for(auto &b:B)cin>>b;
  vi hog;
  dfs2(0,0,hog);
  dfs(0,0,hog);
  //cout<<win<<" "<<sum<<endl;
  printf("%.10f\n",(win)/(sum));
  return 0;
}
            
            
            
        