結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-08-22 16:48:34 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,999 bytes |
| コンパイル時間 | 169 ms |
| コンパイル使用メモリ | 32,896 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 14:09:10 |
| 合計ジャッジ時間 | 1,463 ms |
|
ジャッジサーバーID (参考情報) |
judge / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 1 |
コンパイルメッセージ
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();
| ^~
ソースコード
// 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++;
}
printf("%.5lf\n", ((double)ans) / LOOP);
return 0;
}
bal4u