結果
問題 | No.913 木の燃やし方 |
ユーザー | roaris |
提出日時 | 2023-03-16 06:04:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,620 bytes |
コンパイル時間 | 561 ms |
コンパイル使用メモリ | 81,740 KB |
実行使用メモリ | 120,736 KB |
最終ジャッジ日時 | 2023-10-18 12:53:26 |
合計ジャッジ時間 | 30,426 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
53,648 KB |
testcase_01 | AC | 42 ms
53,668 KB |
testcase_02 | AC | 45 ms
53,636 KB |
testcase_03 | AC | 216 ms
78,044 KB |
testcase_04 | AC | 221 ms
77,956 KB |
testcase_05 | WA | - |
testcase_06 | AC | 200 ms
77,504 KB |
testcase_07 | AC | 144 ms
76,820 KB |
testcase_08 | AC | 1,003 ms
114,220 KB |
testcase_09 | AC | 917 ms
111,796 KB |
testcase_10 | AC | 893 ms
111,816 KB |
testcase_11 | AC | 916 ms
114,008 KB |
testcase_12 | AC | 939 ms
116,100 KB |
testcase_13 | AC | 787 ms
115,312 KB |
testcase_14 | AC | 762 ms
111,624 KB |
testcase_15 | AC | 753 ms
111,616 KB |
testcase_16 | AC | 846 ms
115,512 KB |
testcase_17 | AC | 826 ms
112,276 KB |
testcase_18 | AC | 809 ms
111,760 KB |
testcase_19 | AC | 600 ms
117,568 KB |
testcase_20 | AC | 812 ms
115,952 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 543 ms
117,908 KB |
testcase_26 | AC | 774 ms
117,592 KB |
testcase_27 | AC | 544 ms
120,736 KB |
testcase_28 | AC | 917 ms
119,492 KB |
testcase_29 | AC | 983 ms
119,300 KB |
testcase_30 | WA | - |
testcase_31 | AC | 647 ms
118,108 KB |
testcase_32 | AC | 643 ms
117,244 KB |
testcase_33 | AC | 669 ms
119,224 KB |
testcase_34 | AC | 861 ms
104,512 KB |
testcase_35 | AC | 888 ms
104,272 KB |
testcase_36 | AC | 822 ms
119,104 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**19 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**19 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**19]*N dfs(0, N) for i in range(N): print(ans[i])