結果

問題 No.173 カードゲーム(Medium)
ユーザー bal4ubal4u
提出日時 2019-08-22 17:35:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 2,053 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 33,280 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 19:09:33
合計ジャッジ時間 1,269 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 74 ms
6,940 KB
testcase_03 AC 74 ms
6,940 KB
testcase_04 AC 72 ms
6,944 KB
testcase_05 AC 56 ms
6,944 KB
testcase_06 AC 39 ms
6,944 KB
testcase_07 AC 32 ms
6,940 KB
testcase_08 AC 33 ms
6,944 KB
testcase_09 AC 96 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: note: in expansion of macro 'gc'
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.173 カードゲーム(Medium)
// 2019.8.22 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

double getdbl() { // 実数の入力
	int minus = 0;
	double x, y;
	int n = 0, c = gc();
	if (c == '-') minus = 1, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	if (c == '.') {
		x = 0;
		y = 1, c = gc();
		do y *= 0.1, x += y * (c & 0xf), c = gc(); while (c >= '0');
		x += n;
	} else x = n;
	if (minus) x = -x;
	return x;
}

#define MAX 1000
#define LOOP 50000
int N;
int A[25], B[25];  // それぞれの最大値
double Pa, Pb;
int a[25], b[25];

int cmp(const void *u, const void *v) { return *(int *)u - *(int *)v; }

// 32ビット乱数を生成する
unsigned int xorshift(void) {
	static unsigned int y = 2463534242;
	y = y ^ (y << 13);
	y = y ^ (y >> 17);
	y = y ^ (y << 5);
	return y;
}

static int f[25];
void setup(int *a, int *A, double P) {
	int i, j, k; double p;
	memcpy(f, A, sizeof(f));
	for (i = 1; i < N; i++) {
		p = (xorshift() % (MAX+1)) / (double)MAX;
		if (p <= P) j = 0;
		else j = 1+(N-i)*(p-P)/(1-P);

		if (j > N-i) j = N-i;
		
		for (k = 0; k < N; k++) {
			if (f[k] && j-- == 0) {
				a[i-1] = f[k], f[k] = 0;
				break;
			}
		}
	}
	for (k = 0; k < N; k++) {
		if (f[k]) { a[N-1] = f[k]; break; }
	}
}

int main()
{
	int i, loop, sa, sb, ans;

	N = in(), Pa = getdbl(), Pb = getdbl();
	i = N; while (i--) A[i] = in();
	i = N; while (i--) B[i] = in();
	qsort(A, N, sizeof(int), cmp), qsort(B, N, sizeof(int), cmp);

	ans = 0, loop = LOOP; while (loop--) {
		sa = sb = 0;
		setup(a, A, Pa), setup(b, B, Pb);
		for (i = 0; i < N; i++) {
			int t = a[i] - b[i];
			if (t > 0) sa += a[i] + b[i];
			else if (t < 0) sb += a[i] + b[i];
		}
		if (sa > sb) ans++;
	}
	ans = (ans+50)*10000 / LOOP;
	if (ans >= 10000) puts("1.0000");
	else printf("0.%04d\n", ans);
	return 0;
}
0