結果
問題 | No.2006 Decrease All to Zero |
ユーザー | to-omer |
提出日時 | 2022-07-01 18:37:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 898 ms / 4,000 ms |
コード長 | 2,334 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 86,320 KB |
最終ジャッジ日時 | 2024-11-14 11:48:20 |
合計ジャッジ時間 | 10,343 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,076 KB |
testcase_01 | AC | 37 ms
52,864 KB |
testcase_02 | AC | 113 ms
76,260 KB |
testcase_03 | AC | 41 ms
53,916 KB |
testcase_04 | AC | 40 ms
53,684 KB |
testcase_05 | AC | 39 ms
53,228 KB |
testcase_06 | AC | 83 ms
76,528 KB |
testcase_07 | AC | 84 ms
76,328 KB |
testcase_08 | AC | 43 ms
54,872 KB |
testcase_09 | AC | 43 ms
55,272 KB |
testcase_10 | AC | 594 ms
84,340 KB |
testcase_11 | AC | 866 ms
86,096 KB |
testcase_12 | AC | 613 ms
83,384 KB |
testcase_13 | AC | 604 ms
83,072 KB |
testcase_14 | AC | 898 ms
86,320 KB |
testcase_15 | AC | 866 ms
85,192 KB |
testcase_16 | AC | 485 ms
80,676 KB |
testcase_17 | AC | 700 ms
83,704 KB |
testcase_18 | AC | 38 ms
53,596 KB |
testcase_19 | AC | 38 ms
52,516 KB |
testcase_20 | AC | 39 ms
52,868 KB |
testcase_21 | AC | 40 ms
53,828 KB |
testcase_22 | AC | 38 ms
54,008 KB |
testcase_23 | AC | 38 ms
53,724 KB |
testcase_24 | AC | 39 ms
53,752 KB |
testcase_25 | AC | 40 ms
52,872 KB |
testcase_26 | AC | 673 ms
85,732 KB |
testcase_27 | AC | 790 ms
78,292 KB |
testcase_28 | AC | 811 ms
78,416 KB |
testcase_29 | AC | 196 ms
78,804 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 = max(A[i] - 2 + j, int(j == 2)), min(M, A[i] + 1 - nj + j) for k in range(R - 1, L - 1, -1): que.appendleft(DP[j][k]) 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()