結果

問題 No.913 木の燃やし方
ユーザー roarisroaris
提出日時 2023-03-16 05:19:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,809 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 80,716 KB
最終ジャッジ日時 2023-10-18 12:48:33
合計ジャッジ時間 9,984 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,824 KB
testcase_01 AC 45 ms
53,856 KB
testcase_02 AC 41 ms
53,800 KB
testcase_03 AC 281 ms
79,476 KB
testcase_04 AC 277 ms
79,928 KB
testcase_05 WA -
testcase_06 AC 196 ms
79,024 KB
testcase_07 AC 141 ms
77,232 KB
testcase_08 TLE -
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
input = sys.stdin.readline
from collections import *

class CHT: #傾きの単調性と最小値クエリのxの単調性を仮定
    def __init__(self):
        self.q = deque([]) #直線群
        
    def f(self, f1, x): #直線f1のxの値
        return f1[0]*x+f1[1]
    
    def check(self, f1, f2, f3): #f2を削除しても良いかの判定
        return (f2[0]-f1[0])*(f3[1]-f2[1])>=(f2[1]-f1[1])*(f3[0]-f2[0])
    
    def add_line(self, a, b): #傾きa, 切片bの直線を追加
        while len(self.q)>=2 and self.check(self.q[-2], self.q[-1], (a, b)):
            self.q.pop()
        
        self.q.append((a, b))
    
    def get(self, x): #xでの最小値
        while len(self.q)>=2 and self.f(self.q[0], x)>=self.f(self.q[1], x):
            self.q.popleft()
        
        return self.f(self.q[0], x)

def dfs(l, r): # [l, r)
    global ans
    
    if r-l==1:
        ans[l] = min(ans[l], 1+A[l])
        return

    m = (l+r)//2
    # [l, m)
    cht = CHT()
    left = [10**18]*N
    
    for i in range(m+1, r+1):
        cht.add_line(-2*i, i*i+acc[i])
    
    for i in range(l, m):
        left[i] = cht.get(i)+i*i-acc[i]
        
        if i>l:
            left[i] = min(left[i], left[i-1])
    
    # [m, r)
    cht = CHT()
    right = [10**18]*(N+1)
    
    for i in range(l, m+1):
        cht.add_line(-2*i, i*i-acc[i])
    
    for i in range(r, m, -1):
        right[i] = cht.get(i)+i*i+acc[i]
        
        if i<r:
            right[i] = min(right[i], right[i+1])
    
    for i in range(N):
        ans[i] = min(ans[i], left[i], right[i+1])
    
    dfs(l, m)
    dfs(m, r)
    
N = int(input())
A = list(map(int, input().split()))
acc = [0]

for Ai in A:
    acc.append(acc[-1]+Ai)

ans = [10**18]*N
dfs(0, N)

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