結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
4,376 KB
testcase_01 AC 159 ms
4,380 KB
testcase_02 AC 1,238 ms
4,380 KB
testcase_03 AC 1,208 ms
4,380 KB
testcase_04 AC 1,191 ms
4,376 KB
testcase_05 AC 1,040 ms
4,380 KB
testcase_06 AC 885 ms
4,380 KB
testcase_07 AC 802 ms
4,376 KB
testcase_08 AC 804 ms
4,376 KB
testcase_09 AC 1,403 ms
4,376 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 pa,pb;
  scanf("%d %f %f",&n,&pa,&pb);
  //printf("%d %d %d\n",n,pa,pb);
  //cout<<pa*1000<<" "<<pb*1000<<endl;

  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*1000) ida=nx(mt);
        if(y>pb*1000) idb=nx(mt);       
      }
      assert(ida<(int)ta.size());
      assert(idb<(int)tb.size());
      
      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