結果
問題 | No.2006 Decrease All to Zero |
ユーザー | to-omer |
提出日時 | 2022-07-01 18:28:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,166 ms / 4,000 ms |
コード長 | 2,186 bytes |
コンパイル時間 | 343 ms |
コンパイル使用メモリ | 82,584 KB |
実行使用メモリ | 101,536 KB |
最終ジャッジ日時 | 2024-11-14 11:48:01 |
合計ジャッジ時間 | 13,760 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,200 KB |
testcase_01 | AC | 39 ms
53,420 KB |
testcase_02 | AC | 151 ms
77,960 KB |
testcase_03 | AC | 40 ms
53,456 KB |
testcase_04 | AC | 39 ms
53,292 KB |
testcase_05 | AC | 40 ms
53,540 KB |
testcase_06 | AC | 87 ms
76,732 KB |
testcase_07 | AC | 96 ms
76,416 KB |
testcase_08 | AC | 45 ms
55,496 KB |
testcase_09 | AC | 45 ms
55,780 KB |
testcase_10 | AC | 1,134 ms
99,352 KB |
testcase_11 | AC | 1,116 ms
88,892 KB |
testcase_12 | AC | 1,151 ms
101,408 KB |
testcase_13 | AC | 1,136 ms
98,376 KB |
testcase_14 | AC | 1,123 ms
89,836 KB |
testcase_15 | AC | 1,092 ms
90,360 KB |
testcase_16 | AC | 539 ms
81,560 KB |
testcase_17 | AC | 877 ms
87,140 KB |
testcase_18 | AC | 38 ms
52,808 KB |
testcase_19 | AC | 38 ms
53,148 KB |
testcase_20 | AC | 39 ms
54,324 KB |
testcase_21 | AC | 39 ms
52,872 KB |
testcase_22 | AC | 39 ms
54,696 KB |
testcase_23 | AC | 39 ms
53,008 KB |
testcase_24 | AC | 39 ms
53,016 KB |
testcase_25 | AC | 39 ms
53,156 KB |
testcase_26 | AC | 1,166 ms
101,536 KB |
testcase_27 | AC | 793 ms
77,628 KB |
testcase_28 | AC | 809 ms
77,968 KB |
testcase_29 | AC | 184 ms
78,040 KB |
ソースコード
import sys input = sys.stdin.buffer.readline INF = 10 ** 18 class QueueAggregation: def __init__(self, e, f): self.e = e self.f = f self.front = [] self.back = [] def fold_all(self): return self.f( self.front[-1][0] if self.front else self.e, self.back[-1][0] if self.back else self.e, ) def append(self, val): x = self.f( self.back[-1][0] if self.back else self.e, val, ) self.back.append((x, val)) def appendleft(self, val): x = self.f( val, self.front[-1][0] if self.front else self.e, ) self.front.append((x, val)) def pop(self): if not self.front: while self.back: _, val = self.back.pop() self.appendleft(val) return self.front.pop()[1] def main(): N = int(input()) X = list(map(int, input().split())) A = list(map(int, input().split())) M = max(A) + 1 DP = [[INF] * M for _ in range(3)] EP = [[INF] * M for _ in range(3)] for j in range(3): DP[j][A[0] * 2 - 2 >> 1] = 0 for i in range(1, N): w = X[i] - X[i - 1] for j in range(3): for k in range(M): DP[j][k] += (k * 2 + 2 - j) * w EP[j][k] = INF for j in range(3): for nj in range(j, 3): que = QueueAggregation(INF, min) L, R = 0, 0 for nk in range(M): nL = max(nk - A[i], A[i] - nk - 2 + j, int(j == 2)) nR = min(M, nk + A[i] + 1 - nj + j) while L > nL: L -= 1 que.appendleft(DP[j][L]) while R < nR: que.append(DP[j][R]) R += 1 while L < nL: que.pop() L += 1 EP[nj][nk] = min(EP[nj][nk], que.fold_all()) DP, EP = EP, DP ANS = DP[2][0] if ANS >= INF: ANS = -1 print(ANS) if __name__ == "__main__": main()