結果

問題 No.133 カードゲーム
ユーザー mamumamura1mamumamura1
提出日時 2019-02-23 12:11:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,148 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 173,448 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-19 17:47:43
合計ジャッジ時間 2,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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