結果

問題 No.913 木の燃やし方
ユーザー roarisroaris
提出日時 2023-03-16 05:25:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,784 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 234,836 KB
最終ジャッジ日時 2023-10-18 12:49:23
合計ジャッジ時間 48,470 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,844 KB
testcase_01 AC 41 ms
53,892 KB
testcase_02 AC 41 ms
53,816 KB
testcase_03 AC 189 ms
78,772 KB
testcase_04 AC 197 ms
78,492 KB
testcase_05 WA -
testcase_06 AC 183 ms
78,440 KB
testcase_07 AC 155 ms
77,476 KB
testcase_08 AC 1,487 ms
188,972 KB
testcase_09 AC 1,427 ms
190,036 KB
testcase_10 AC 1,426 ms
188,204 KB
testcase_11 AC 1,463 ms
191,584 KB
testcase_12 AC 1,550 ms
194,104 KB
testcase_13 AC 1,432 ms
187,864 KB
testcase_14 AC 1,386 ms
185,300 KB
testcase_15 AC 1,378 ms
185,388 KB
testcase_16 AC 1,482 ms
213,604 KB
testcase_17 AC 1,475 ms
214,244 KB
testcase_18 AC 1,433 ms
211,696 KB
testcase_19 AC 1,248 ms
234,836 KB
testcase_20 AC 1,497 ms
220,432 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1,246 ms
227,592 KB
testcase_26 AC 1,437 ms
195,592 KB
testcase_27 AC 1,206 ms
215,028 KB
testcase_28 AC 1,534 ms
182,932 KB
testcase_29 AC 1,573 ms
188,168 KB
testcase_30 WA -
testcase_31 AC 1,323 ms
213,464 KB
testcase_32 AC 1,329 ms
213,216 KB
testcase_33 AC 1,342 ms
215,424 KB
testcase_34 AC 1,558 ms
200,252 KB
testcase_35 AC 1,568 ms
200,956 KB
testcase_36 AC 1,547 ms
207,696 KB
権限があれば一括ダウンロードができます

ソースコード

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 = defaultdict(lambda: 10**18)
    
    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]
        left[i] = min(left[i], left[i-1])
    
    # [m, r)
    cht = CHT()
    right = defaultdict(lambda: 10**18)
    
    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]
        right[i] = min(right[i], right[i+1])
    
    for i in range(l, r):
        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