結果

問題 No.913 木の燃やし方
ユーザー treeonetreeone
提出日時 2019-10-18 18:07:37
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,739 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 80,276 KB
最終ジャッジ日時 2023-09-07 21:00:17
合計ジャッジ時間 11,356 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,440 KB
testcase_01 AC 66 ms
71,480 KB
testcase_02 AC 66 ms
71,252 KB
testcase_03 AC 207 ms
80,276 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

# https://atcoder.jp/contests/dp/submissions/6934013
class ConvexHullTrickAddMonotone:
	def __init__(self):
		self.AB = []
 
	def check(self,a,b):
		a1,b1 = self.AB[-1][0],self.AB[-1][1]
		a2,b2 = self.AB[-2][0],self.AB[-2][1]
		lhs = (b2-b1)*(a -a1)
		rhs = (b1-b )*(a1-a2)
		return lhs>=rhs
 
	# 一次関数 y=a*x+b を追加 (傾きaは単調減少)
	def add_line(self,a,b):
		while 2<=len(self.AB) and self.check(a,b):
			self.AB.pop()
		self.AB.append((a,b))
		return
	# min_i {a[i]*x+b[i]}
	def query(self,x):
		def eval(ab,x):
			return ab[0]*x+ab[1]
		l,r = -1, len(self.AB)-1
		while l+1<r:
			m = (l+r)//2
			if eval(self.AB[m+1],x)<=eval(self.AB[m],x):
				l = m
			else:
				r = m
		return eval(self.AB[r],x)

N = int(input())
A = [int(i) for i in input().split()]
S = [0] * (N + 1)
ans = [1e18] * N
tmp = [0] * (N + 1)

for i in range(1, N + 1):
    S[i] = S[i - 1] + A[i - 1]

def calc(L, R):
    if L >= R:
        return
    M = (L + R) // 2
    calc(L, M)
    calc(M + 1, R)

    if L < M:
        cht = ConvexHullTrickAddMonotone()
        for l in range(M + 1, R + 1):
            cht.add_line(-2 * l, l * l + S[l])
        MIN = 1e18
        for k in range(L, M):
            MIN = min(MIN, cht.query(k) + k * k - S[k])
            ans[k] = min(ans[k], MIN)
    if M < R:
        cht = ConvexHullTrickAddMonotone()
        for k in range(L, M + 1):
            cht.add_line(-2 * k, k * k - S[k])
        MIN = 1e18
        for l in range(M + 1, R + 1):
            tmp[l] = cht.query(l) + l * l + S[l]
        for l in range(R, M, -1):
            MIN = min(MIN, tmp[l])
            ans[l - 1] = min(ans[l - 1], MIN)
    return

calc(0, N)

for i in range(N):
    print(ans[i])
0