結果

問題 No.913 木の燃やし方
ユーザー roarisroaris
提出日時 2023-03-16 06:01:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,553 bytes
コンパイル時間 1,425 ms
コンパイル使用メモリ 81,044 KB
実行使用メモリ 120,108 KB
最終ジャッジ日時 2023-10-18 12:51:56
合計ジャッジ時間 28,457 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,564 KB
testcase_01 AC 41 ms
53,600 KB
testcase_02 AC 41 ms
53,544 KB
testcase_03 AC 166 ms
77,612 KB
testcase_04 AC 172 ms
78,552 KB
testcase_05 WA -
testcase_06 AC 158 ms
77,344 KB
testcase_07 AC 136 ms
76,836 KB
testcase_08 AC 874 ms
114,924 KB
testcase_09 AC 857 ms
111,328 KB
testcase_10 AC 840 ms
111,212 KB
testcase_11 AC 853 ms
113,016 KB
testcase_12 AC 884 ms
115,088 KB
testcase_13 AC 816 ms
114,416 KB
testcase_14 AC 770 ms
111,256 KB
testcase_15 AC 778 ms
111,256 KB
testcase_16 AC 819 ms
114,916 KB
testcase_17 AC 822 ms
111,332 KB
testcase_18 AC 785 ms
111,332 KB
testcase_19 AC 580 ms
120,108 KB
testcase_20 AC 866 ms
115,060 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 543 ms
118,644 KB
testcase_26 AC 807 ms
117,180 KB
testcase_27 AC 555 ms
120,100 KB
testcase_28 AC 944 ms
119,488 KB
testcase_29 AC 886 ms
119,516 KB
testcase_30 WA -
testcase_31 AC 656 ms
115,096 KB
testcase_32 AC 661 ms
117,276 KB
testcase_33 AC 734 ms
119,420 KB
testcase_34 AC 911 ms
104,556 KB
testcase_35 AC 858 ms
104,480 KB
testcase_36 AC 874 ms
119,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

class CHT:
    def __init__(self):
        self.deq = deque()
        
    def check(self, f1, f2, f3):
        return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0])
    
    def f(self, f1, x):
        return f1[0]*x + f1[1]
    
    # add f_i(x) = a*x + b
    def add_line(self, a, b):
        f1 = (a, b)
        while len(self.deq) >= 2 and self.check(self.deq[-2], self.deq[-1], f1):
            self.deq.pop()
        self.deq.append(f1)
    
    # min f_i(x)
    def get(self, x):
        while len(self.deq) >= 2 and self.f(self.deq[0], x) >= self.f(self.deq[1], x):
            self.deq.popleft()
        return self.f(self.deq[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()
    
    for i in range(m+1, r+1):
        cht.add_line(-2*i, i*i+acc[i])
    
    res = 10**18
    
    for i in range(l, m):
        res = min(res, cht.get(i)+i*i-acc[i])
        ans[i] = min(ans[i], res)
    
    # [m, r)
    cht = CHT()
    
    for i in range(l, m+1):
        cht.add_line(-2*i, i*i-acc[i])
    
    res = 10**18
    
    for i in range(r, m, -1):
        res = min(res, cht.get(i)+i*i+acc[i])
        ans[i-1] = min(ans[i-1], res)
    
    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