結果

問題 No.173 カードゲーム(Medium)
ユーザー 0w10w1
提出日時 2017-01-05 14:32:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,651 ms / 3,000 ms
コード長 1,867 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 173,068 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 12:27:07
合計ジャッジ時間 12,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,384 KB
testcase_01 AC 164 ms
4,376 KB
testcase_02 AC 1,345 ms
4,376 KB
testcase_03 AC 1,344 ms
4,376 KB
testcase_04 AC 1,302 ms
4,376 KB
testcase_05 AC 1,115 ms
4,376 KB
testcase_06 AC 871 ms
4,376 KB
testcase_07 AC 745 ms
4,376 KB
testcase_08 AC 748 ms
4,384 KB
testcase_09 AC 1,651 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< int, int > pii;
typedef vector< pii > vp;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< string > vs;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N;
double Pa, Pb;
vi A;
vi B;

void init(){
  cin >> N;
  cin >> Pa >> Pb;
  A = B = vi( N );
  for( int i = 0; i < N; ++i ){
    cin >> A[ i ];
  }
  for( int i = 0; i < N; ++i ){
    cin >> B[ i ];
  }
}

void preprocess(){
  sort( A.begin(), A.end() );
  sort( B.begin(), B.end() );
}

void solve(){
  srand( time( NULL ) );
  int win = 0;
  int trial = ( int ) 1e6;
  for( int kase = 0; kase < trial; ++kase ){
    int asum = 0, bsum = 0;
    vi a = A, b = B;
    for( int i = 0; i < N - 1; ++i ){
      int aid, bid;
      if( rand() % 1000 < Pa * 1000 ){
        aid = 0;
      } else{
        aid = rand() % ( a.size() - 1 ) + 1;
      }
      if( rand() % 1000 < Pb * 1000 ){
        bid = 0;
      } else{
        bid = rand() % ( b.size() - 1 ) + 1;
      }
      if( a[ aid ] > b[ bid ] ){
        asum += a[ aid ] + b[ bid ];
      } else{
        bsum += a[ aid ] + b[ bid ];
      }
      a.erase( a.begin() + aid );
      b.erase( b.begin() + bid );
    }
    if( a[ 0 ] > b[ 0 ] ){
      asum += a[ 0 ] + b[ 0 ];
    } else{
      bsum += a[ 0 ] + b[ 0 ];
    }
    if( asum > bsum ){
      ++win;
    }
  }
  cout << fixed << setprecision( 7 ) << 1.0 * win / trial << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0