結果
問題 | No.913 木の燃やし方 |
ユーザー | roaris |
提出日時 | 2023-03-16 06:03:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,620 bytes |
コンパイル時間 | 674 ms |
コンパイル使用メモリ | 80,356 KB |
実行使用メモリ | 119,760 KB |
最終ジャッジ日時 | 2023-10-18 12:52:54 |
合計ジャッジ時間 | 28,719 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,772 KB |
testcase_01 | AC | 42 ms
53,832 KB |
testcase_02 | AC | 43 ms
53,748 KB |
testcase_03 | AC | 215 ms
78,540 KB |
testcase_04 | AC | 207 ms
78,168 KB |
testcase_05 | WA | - |
testcase_06 | AC | 182 ms
77,336 KB |
testcase_07 | AC | 131 ms
76,900 KB |
testcase_08 | AC | 909 ms
115,532 KB |
testcase_09 | AC | 820 ms
111,828 KB |
testcase_10 | AC | 849 ms
111,788 KB |
testcase_11 | AC | 866 ms
114,028 KB |
testcase_12 | AC | 906 ms
116,124 KB |
testcase_13 | AC | 773 ms
115,492 KB |
testcase_14 | AC | 741 ms
111,764 KB |
testcase_15 | AC | 757 ms
111,764 KB |
testcase_16 | AC | 798 ms
115,628 KB |
testcase_17 | AC | 771 ms
112,028 KB |
testcase_18 | AC | 781 ms
111,832 KB |
testcase_19 | AC | 554 ms
117,688 KB |
testcase_20 | AC | 784 ms
116,096 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 505 ms
118,160 KB |
testcase_26 | AC | 777 ms
117,728 KB |
testcase_27 | AC | 543 ms
119,760 KB |
testcase_28 | AC | 874 ms
119,680 KB |
testcase_29 | AC | 913 ms
119,548 KB |
testcase_30 | WA | - |
testcase_31 | AC | 634 ms
115,916 KB |
testcase_32 | AC | 650 ms
117,408 KB |
testcase_33 | AC | 646 ms
118,260 KB |
testcase_34 | AC | 836 ms
104,756 KB |
testcase_35 | AC | 877 ms
104,416 KB |
testcase_36 | AC | 821 ms
119,316 KB |
ソースコード
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 l>=r: return m = (l+r)//2 dfs(l, m) dfs(m+1, r) # [l, m) if 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) if 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) 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])