結果

問題 No.731 等差数列がだいすき
ユーザー simamumusimamumu
提出日時 2018-09-07 22:56:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 270 ms / 1,500 ms
コード長 1,454 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 87,396 KB
実行使用メモリ 84,692 KB
最終ジャッジ日時 2023-08-19 21:50:50
合計ジャッジ時間 7,783 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 264 ms
84,312 KB
testcase_01 AC 268 ms
84,388 KB
testcase_02 AC 262 ms
84,692 KB
testcase_03 AC 262 ms
84,612 KB
testcase_04 AC 260 ms
84,148 KB
testcase_05 AC 259 ms
84,164 KB
testcase_06 AC 262 ms
84,276 KB
testcase_07 AC 261 ms
84,268 KB
testcase_08 AC 270 ms
84,572 KB
testcase_09 AC 265 ms
84,220 KB
testcase_10 AC 263 ms
84,160 KB
testcase_11 AC 267 ms
84,388 KB
testcase_12 AC 261 ms
84,416 KB
testcase_13 AC 264 ms
84,156 KB
testcase_14 AC 262 ms
84,692 KB
testcase_15 AC 258 ms
84,500 KB
testcase_16 AC 264 ms
84,256 KB
testcase_17 AC 258 ms
84,064 KB
testcase_18 AC 258 ms
84,420 KB
testcase_19 AC 263 ms
84,328 KB
testcase_20 AC 259 ms
84,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = inpl()

SUMa = sum(aa)
SUM2a = 0
SUMaa = 0
for i in range(N):
	SUM2a += aa[i]*(2*i)
	SUMaa += aa[i]**2

def calc(A,d):
	tmp = SUMaa - 2*SUMa*A - SUM2a*d
	tmp += A**2*N		#A^2
	tmp += (N-1)*N*A*d	#2Ad
	tmp += (N-1)*N*(2*N-1)//6*d**2 #d^2
	return tmp

def calc_d(A):
	xx =[0]*4
	xx[0] = -10**7
	xx[3] = 10**7
	xx[1] = (xx[0]*2 + xx[3]) /3
	xx[2] = (xx[0] + xx[3]*2) /3

	yy = [0]*4
	for i in range(4):
		yy[i] = calc(A,xx[i])

	for _ in range(300):
		if yy[1] < yy[2]:
			xx[3] = xx[2]
			xx[1] = (xx[0]*2 + xx[3]) /3
			xx[2] = (xx[0] + xx[3]*2) /3
		else:
			xx[0] = xx[1]
			xx[1] = (xx[0]*2 + xx[3]) /3
			xx[2] = (xx[0] + xx[3]*2) /3

		yy[1] = calc(A,xx[1])
		yy[2] = calc(A,xx[2])

	return yy[1],xx[1]


xx =[0]*4
xx[0] = -10**10
xx[3] = 10**10
xx[1] = (xx[0]*2 + xx[3]) /3
xx[2] = (xx[0] + xx[3]*2) /3

yy = [0]*4
for i in range(4):
	yy[i],d = calc_d(xx[i])
by = yy[1]

for _ in range(1000):
	if yy[1] < yy[2]:
		xx[3] = xx[2]
		xx[1] = (xx[0]*2 + xx[3]) /3
		xx[2] = (xx[0] + xx[3]*2) /3
	else:
		xx[0] = xx[1]
		xx[1] = (xx[0]*2 + xx[3]) /3
		xx[2] = (xx[0] + xx[3]*2) /3

	yy[1],d = calc_d(xx[1])
	yy[2],d = calc_d(xx[2])


print(xx[1],d)
print(yy[1])
0