結果

問題 No.1682 Unfair Game
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-09-20 14:39:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,632 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 71,372 KB
最終ジャッジ日時 2023-09-15 10:12:36
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,128 KB
testcase_01 AC 74 ms
71,076 KB
testcase_02 AC 77 ms
70,992 KB
testcase_03 AC 75 ms
71,172 KB
testcase_04 AC 75 ms
71,008 KB
testcase_05 AC 77 ms
71,064 KB
testcase_06 AC 76 ms
71,296 KB
testcase_07 AC 75 ms
70,992 KB
testcase_08 AC 77 ms
71,056 KB
testcase_09 AC 77 ms
71,264 KB
testcase_10 AC 73 ms
71,152 KB
testcase_11 AC 76 ms
71,280 KB
testcase_12 AC 75 ms
71,152 KB
testcase_13 AC 73 ms
71,228 KB
testcase_14 AC 73 ms
71,288 KB
testcase_15 AC 73 ms
71,300 KB
testcase_16 AC 75 ms
71,168 KB
testcase_17 AC 73 ms
71,060 KB
testcase_18 AC 74 ms
70,992 KB
testcase_19 AC 75 ms
71,076 KB
testcase_20 AC 73 ms
71,108 KB
testcase_21 AC 73 ms
71,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1682

1/2 のコインは含んではいけない。

現在、奇数の確率が1/2より小さく
1/2 - x であるとしよう。(0 <= x <= 1/2)
偶数は
1/2 + x である。

pのコインを投げるとどうなるか?

奇数は
(1/2-x) * (1-p) + (1/2+x)*p = 1/2 - x - p/2 + px + p/2 + px = 1/2 - x + 2px
偶数は
(1/2-x) * p + (1/2+x)*(1-p) = p/2 - px + 1/2 + x - p/2 - px = 1/2 + x - 2px

つまり、2px変化する。
p > 1/2 の時、奇数の確率は1/2より大きくなる。
p < 1/2 の時、奇数の確率の1/2との大小は変化しない。


1/2より大きいのコインを奇数枚選べばよい。
1/2未満のコインは適当にとればよい

"""

import sys
from sys import stdin


def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod

mod = 10**9+7
fac,inv = modfac(1000,mod)

N = int(stdin.readline())
P = list(map(int,stdin.readline().split()))

mod = 10**9+7

odd = 0
eve = 0

for i in P:
    if i > 50:
        odd += 1
    elif i < 50:
        eve += 1

ans = 0
ep = pow(2,eve,mod)
for o in range(1,odd+1,2):
    ans += modnCr(odd,o,mod,fac,inv) * ep

print (ans % mod)
0