結果

問題 No.173 カードゲーム(Medium)
ユーザー nanasilinanasili
提出日時 2015-04-10 11:06:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,902 ms / 3,000 ms
コード長 1,670 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 83,696 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 19:08:42
合計ジャッジ時間 34,083 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,901 ms
4,380 KB
testcase_01 AC 2,902 ms
4,380 KB
testcase_02 AC 2,902 ms
4,376 KB
testcase_03 AC 2,902 ms
4,380 KB
testcase_04 AC 2,901 ms
4,376 KB
testcase_05 AC 2,902 ms
4,380 KB
testcase_06 AC 2,902 ms
4,376 KB
testcase_07 AC 2,901 ms
4,376 KB
testcase_08 AC 2,901 ms
4,376 KB
testcase_09 AC 2,902 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

// #include <sys/time.h>
ll getTimeUS() {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (ll)tv.tv_sec*1000000+(ll)tv.tv_usec;
}

int drawcard(int *card, int p, int n) {
  int minp = 0;
  for (int i = 1; i < n; i++) {
    if (card[i] < card[minp]) {
      minp = i;
    }
  }

  if (n == 1) {
    return 0;
  }else if (rand()%1000 < p) {
    return minp;
  }else {
    swap(card[minp], card[n-1]);
    return rand()%(n-1);
  }
}

int main() {
  ll startT = getTimeUS();

  int n;
  cin >> n;
  double ta, tb;
  cin >> ta >> tb;
  int pa = ta*1000, pb = tb*1000;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  double cnt1, cnt2;
  cnt1 = cnt2 = 0;
  while (getTimeUS()-startT < 1000000*3-100000) {
    int suma, sumb;
    suma = sumb = 0;
    for (int i = 0; i < n; i++) {
      int carda, cardb;
      int p;
      p = drawcard(a, pa, n-i);
      carda = a[p];
      swap(a[p], a[n-1-i]);
      p = drawcard(b, pb, n-i);
      cardb = b[p];
      swap(b[p], b[n-1-i]);
      if (carda < cardb) {
	sumb += carda+cardb;
      }else {
	suma += carda+cardb;
      }
    }
    if (suma > sumb) {
      cnt1++;
    }
    cnt2++;
  }
  std::cout << cnt1/cnt2 << std::endl;
}
0