結果

問題 No.173 カードゲーム(Medium)
ユーザー beetbeet
提出日時 2019-04-06 18:07:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,452 ms / 3,000 ms
コード長 1,225 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 206,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 15:48:46
合計ジャッジ時間 12,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
4,380 KB
testcase_01 AC 168 ms
4,380 KB
testcase_02 AC 1,257 ms
4,376 KB
testcase_03 AC 1,235 ms
4,376 KB
testcase_04 AC 1,217 ms
4,380 KB
testcase_05 AC 1,081 ms
4,380 KB
testcase_06 AC 917 ms
4,376 KB
testcase_07 AC 832 ms
4,376 KB
testcase_08 AC 840 ms
4,376 KB
testcase_09 AC 1,452 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  float fpa,fpb;
  scanf("%d %f %f",&n,&fpa,&fpb);

  int pa=fpa*1000;
  int pb=fpb*1000;
  
  vector<int> va(n),vb(n);
  for(int i=0;i<n;i++) cin>>va[i];
  for(int i=0;i<n;i++) cin>>vb[i];
  sort(va.begin(),va.end());
  sort(vb.begin(),vb.end());
  
  random_device rd;
  mt19937 mt{rd()};

  const int MAX = 1e6;  
  uniform_int_distribution<int> ud(1,1000);
  int cnt=0,sum=0;
  for(int t=0;t<MAX;t++){
    int sa=0,sb=0;
    auto ta=va,tb=vb;
    for(int i=1;i<=n;i++){
      int ida=0,idb=0;

      if(i<n){
        uniform_int_distribution<int> nx(1,n-i);
        int x=ud(mt);
        int y=ud(mt);       

        if(x>pa) ida=nx(mt);
        if(y>pb) idb=nx(mt);       
      }
      
      int res=ta[ida]+tb[idb];

      if(ta[ida]>tb[idb]) sa+=res;
      else sb+=res;
        
      ta.erase(ta.begin()+ida);
      tb.erase(tb.begin()+idb);      
    }
    if(sa>sb) cnt++;
    sum++;
  }  

  printf("%.12f\n",(double)cnt/sum);
  return 0;
}
0