結果
問題 | No.704 ゴミ拾い Medium |
ユーザー | maspy |
提出日時 | 2020-04-02 22:08:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 700 ms / 1,500 ms |
コード長 | 1,731 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 184,856 KB |
最終ジャッジ日時 | 2024-06-28 15:20:36 |
合計ジャッジ時間 | 19,174 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,352 KB |
testcase_01 | AC | 42 ms
52,352 KB |
testcase_02 | AC | 42 ms
52,608 KB |
testcase_03 | AC | 42 ms
52,608 KB |
testcase_04 | AC | 42 ms
52,096 KB |
testcase_05 | AC | 43 ms
52,352 KB |
testcase_06 | AC | 42 ms
52,096 KB |
testcase_07 | AC | 42 ms
52,608 KB |
testcase_08 | AC | 43 ms
52,224 KB |
testcase_09 | AC | 42 ms
52,352 KB |
testcase_10 | AC | 43 ms
52,352 KB |
testcase_11 | AC | 43 ms
52,352 KB |
testcase_12 | AC | 42 ms
52,096 KB |
testcase_13 | AC | 42 ms
52,608 KB |
testcase_14 | AC | 96 ms
76,160 KB |
testcase_15 | AC | 87 ms
73,856 KB |
testcase_16 | AC | 84 ms
73,216 KB |
testcase_17 | AC | 93 ms
75,904 KB |
testcase_18 | AC | 85 ms
73,088 KB |
testcase_19 | AC | 91 ms
75,776 KB |
testcase_20 | AC | 85 ms
73,728 KB |
testcase_21 | AC | 91 ms
75,904 KB |
testcase_22 | AC | 80 ms
71,936 KB |
testcase_23 | AC | 86 ms
74,112 KB |
testcase_24 | AC | 609 ms
184,856 KB |
testcase_25 | AC | 700 ms
184,216 KB |
testcase_26 | AC | 654 ms
184,220 KB |
testcase_27 | AC | 628 ms
184,340 KB |
testcase_28 | AC | 678 ms
184,204 KB |
testcase_29 | AC | 606 ms
184,344 KB |
testcase_30 | AC | 657 ms
184,344 KB |
testcase_31 | AC | 684 ms
184,376 KB |
testcase_32 | AC | 632 ms
184,476 KB |
testcase_33 | AC | 647 ms
184,092 KB |
testcase_34 | AC | 619 ms
182,308 KB |
testcase_35 | AC | 618 ms
182,688 KB |
testcase_36 | AC | 615 ms
182,692 KB |
testcase_37 | AC | 607 ms
182,568 KB |
testcase_38 | AC | 613 ms
182,312 KB |
testcase_39 | AC | 614 ms
182,312 KB |
testcase_40 | AC | 619 ms
182,572 KB |
testcase_41 | AC | 609 ms
182,312 KB |
testcase_42 | AC | 624 ms
182,692 KB |
testcase_43 | AC | 619 ms
182,440 KB |
testcase_44 | AC | 42 ms
52,736 KB |
testcase_45 | AC | 42 ms
52,608 KB |
testcase_46 | AC | 540 ms
176,760 KB |
testcase_47 | AC | 634 ms
183,996 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_left class SegTree: """ segment tree with point modification and range product access. """ data_unit = 1 << 30 data_f = min def __init__(self, N): self.N = N self.data = [self.data_unit] * (N + N) def build(self, raw_data): data = self.data f = self.data_f N = self.N data[N:] = raw_data[:] for i in range(N - 1, 0, -1): data[i] = f(data[i << 1], data[i << 1 | 1]) def set_val(self, i, x): data = self.data f = self.data_f i += self.N data[i] = x while i > 1: data[i >> 1] = f(data[i], data[i ^ 1]) i >>= 1 def fold(self, L, R): """ compute for [L, R) """ vL = vR = self.data_unit data = self.data f = self.data_f L += self.N R += self.N while L < R: if L & 1: vL = f(vL, data[L]) L += 1 if R & 1: R -= 1 vR = f(data[R], vR) L >>= 1 R >>= 1 return f(vL, vR) N = int(readline()) A = (0,) + tuple(map(int, readline().split())) X = (0,) + tuple(map(int, readline().split())) Y = (0,) + tuple(map(int, readline().split())) dp = [0] * (N + 1) dp1 = SegTree(N + 1) dp2 = SegTree(N + 1) for i in range(1, N + 1): dp1.set_val(i, dp[i - 1] - X[i] + Y[i]) dp2.set_val(i, dp[i - 1] + X[i] + Y[i]) n = bisect_left(X, A[i], lo=0, hi=i + 1) dp[i] = min(A[i] + dp1.fold(0, n), -A[i] + dp2.fold(n, i + 1)) print(dp[-1])