結果

問題 No.1173 Endangered Species
ユーザー anagohirameanagohirame
提出日時 2020-08-14 23:35:21
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 671 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 74,880 KB
最終ジャッジ日時 2023-08-01 00:12:24
合計ジャッジ時間 11,483 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 291 ms
56,256 KB
testcase_01 AC 289 ms
56,436 KB
testcase_02 AC 288 ms
56,232 KB
testcase_03 AC 290 ms
56,244 KB
testcase_04 AC 290 ms
56,280 KB
testcase_05 AC 289 ms
56,216 KB
testcase_06 AC 292 ms
56,352 KB
testcase_07 AC 292 ms
56,420 KB
testcase_08 AC 290 ms
56,360 KB
testcase_09 AC 291 ms
56,288 KB
testcase_10 AC 296 ms
56,632 KB
testcase_11 AC 290 ms
56,300 KB
testcase_12 AC 296 ms
56,256 KB
testcase_13 AC 290 ms
56,232 KB
testcase_14 AC 318 ms
57,712 KB
testcase_15 AC 312 ms
57,292 KB
testcase_16 AC 479 ms
65,452 KB
testcase_17 AC 599 ms
71,400 KB
testcase_18 AC 660 ms
74,388 KB
testcase_19 AC 671 ms
74,880 KB
testcase_20 AC 606 ms
74,680 KB
testcase_21 AC 614 ms
74,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import log
from scipy import optimize
n = int(input())
p = list(map(float, input().split()))
q = list(map(float, input().split()))
a = list(map(int, input().split()))

def f(x):
	return sum(p[i] * (1-q[i]) / (1-q[i]*x) for i in range(n)) - x

def f_prime(x):
	return sum(p[i] * (1/q[i] - 1) / ((1/q[i] - x)**2) for i in range(n)) - 1

r = optimize.newton(f, 0, fprime=f_prime)
#print(r)
ans = 0
for i in range(n):
	ans += a[i] * log((1-q[i]) / (1-q[i]*r))
print(ans)
0