Submission #23515127
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'''
三分探索の抽象化ライブラリ
domain:= 定義域が整数(0)or実数(1)
searchtype:= 狭義に凹で最大値を求めたい(0)or狭義に凸で最小値を求めたい(1)
f:= 最大または最小にしたい値を返す
l,r:= 探索範囲(l<=r)
eps:= 誤差(整数なら2,実数なら誤差指定による)
iter:= 探索回数
op1:= 割り算の演算子
op2:= 反転させるかどうか(0の時反転)
op3:= 出力での反転
value:= 三分探索の解
args:= fの引数(iterable)…f(i,args)という形でargsを展開
'''
from operator import floordiv,truediv,truth,not_
from math import log
class ternary_search:
def __init__(self,domain,searchtype,f,l,r,eps,args=None):
self.domain=domain
self.searchtype=searchtype
self.f=f
self.l,self.r=l,r
self.iter=int(log((r+1-l)/eps,1.5))+5
self.args=args
self.op1=[floordiv,truediv][domain]
self.op2=[not_,truth][searchtype]
self.op3=[max,min][searchtype]
self.value=self.calc()
def calc(self):
for _ in range(self.iter):
diff=self.op1(self.r-self.l,3)
trisection1=self.l+diff
trisection2=self.r-diff
trisection1_value=self.f(trisection1,self.args)
trisection2_value=self.f(trisection2,self.args)
if self.op2(trisection1_value<=trisection2_value):
self.r=trisection2
if self.op2(trisection1_value>=trisection2_value):
self.l=trisection1
return self.op3([self.l,self.l+self.op1(self.r-self.l,2),self.r],key=lambda x:self.f(x,self.args))
N = int(input())
A = list(map(int, input().split()))
def f(x,arg):
ret=0
for i in range(N):
ret+=x+A[i]-min(A[i],2*x)
return ret/N
e=ternary_search(1,1,f,0,10**20,10**(-7))
print(f(e.value,None))
Submission Info
Submission Time |
|
Task |
B - Insurance |
User |
H20 |
Language |
PyPy3 (7.3.0) |
Score |
500 |
Code Size |
1893 Byte |
Status |
AC |
Exec Time |
356 ms |
Memory |
84140 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00-sample-001.txt, 00-sample-002.txt |
All |
00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt |
Case Name |
Status |
Exec Time |
Memory |
00-sample-001.txt |
AC |
66 ms |
63740 KB |
00-sample-002.txt |
AC |
64 ms |
68100 KB |
01-001.txt |
AC |
55 ms |
63568 KB |
01-002.txt |
AC |
52 ms |
63420 KB |
01-003.txt |
AC |
57 ms |
63716 KB |
01-004.txt |
AC |
244 ms |
78624 KB |
01-005.txt |
AC |
174 ms |
73156 KB |
01-006.txt |
AC |
177 ms |
72944 KB |
01-007.txt |
AC |
149 ms |
71884 KB |
01-008.txt |
AC |
265 ms |
80428 KB |
01-009.txt |
AC |
352 ms |
84016 KB |
01-010.txt |
AC |
351 ms |
83976 KB |
01-011.txt |
AC |
350 ms |
84140 KB |
01-012.txt |
AC |
356 ms |
83952 KB |
01-013.txt |
AC |
352 ms |
83992 KB |
01-014.txt |
AC |
353 ms |
83980 KB |