結果

問題 No.704 ゴミ拾い Medium
ユーザー tpynerivertpyneriver
提出日時 2019-07-05 19:45:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 784 ms / 1,500 ms
コード長 2,652 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 81,184 KB
実行使用メモリ 184,284 KB
最終ジャッジ日時 2023-10-22 03:05:23
合計ジャッジ時間 18,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,252 KB
testcase_01 AC 40 ms
52,256 KB
testcase_02 AC 40 ms
52,260 KB
testcase_03 AC 74 ms
82,112 KB
testcase_04 AC 40 ms
52,324 KB
testcase_05 AC 40 ms
52,328 KB
testcase_06 AC 41 ms
52,320 KB
testcase_07 AC 40 ms
52,316 KB
testcase_08 AC 41 ms
52,324 KB
testcase_09 AC 40 ms
52,324 KB
testcase_10 AC 40 ms
52,324 KB
testcase_11 AC 41 ms
52,332 KB
testcase_12 AC 41 ms
52,316 KB
testcase_13 AC 42 ms
52,324 KB
testcase_14 AC 154 ms
101,840 KB
testcase_15 AC 163 ms
101,488 KB
testcase_16 AC 147 ms
101,808 KB
testcase_17 AC 154 ms
102,072 KB
testcase_18 AC 136 ms
102,200 KB
testcase_19 AC 133 ms
101,672 KB
testcase_20 AC 135 ms
102,200 KB
testcase_21 AC 134 ms
101,612 KB
testcase_22 AC 137 ms
101,936 KB
testcase_23 AC 136 ms
101,672 KB
testcase_24 AC 745 ms
179,964 KB
testcase_25 AC 775 ms
179,956 KB
testcase_26 AC 784 ms
180,468 KB
testcase_27 AC 700 ms
179,976 KB
testcase_28 AC 777 ms
180,544 KB
testcase_29 AC 740 ms
179,952 KB
testcase_30 AC 771 ms
180,436 KB
testcase_31 AC 773 ms
180,720 KB
testcase_32 AC 684 ms
180,448 KB
testcase_33 AC 767 ms
180,336 KB
testcase_34 AC 428 ms
183,824 KB
testcase_35 AC 436 ms
184,060 KB
testcase_36 AC 459 ms
183,932 KB
testcase_37 AC 429 ms
183,972 KB
testcase_38 AC 458 ms
183,980 KB
testcase_39 AC 428 ms
184,152 KB
testcase_40 AC 426 ms
183,996 KB
testcase_41 AC 433 ms
184,100 KB
testcase_42 AC 432 ms
184,284 KB
testcase_43 AC 430 ms
184,028 KB
testcase_44 AC 39 ms
53,408 KB
testcase_45 AC 68 ms
86,028 KB
testcase_46 AC 483 ms
183,812 KB
testcase_47 AC 604 ms
181,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Lichaotree:
    #区間は1-indexed
    #min
    def __init__(self, X):
        self.N = len(X)
        self.N0 = 2**(self.N-1).bit_length()
        self.comp = {v : k for k, v in enumerate(X)}
        self.inf = 10**12
        self.X = X + [self.inf]*(self.N0 - self.N)
        self.data = [None]*(2*self.N0)
        self.size = [0]*self.N0 + [1]*self.N0
        for i in range(self.N0-1, 0, -1):
            self.size[i] = 2*self.size[2*i]
        
    def f(self, line, x):
        return line[0]*x + line[1]

    def _update(self, k, line):
        
        if self.data[k] is None:
            self.data[k] = line
            return
        
        l = k - (1 << (k.bit_length() - 1))
        l = l*self.size[k]
        r = l + self.size[k]

        
        while True:
            if self.data[k] is None:
                self.data[k] = line
                return
            
            m = (l+r)//2
            lx = self.X[l]
            mx = self.X[m]
            rx = self.X[r-1]
            gl = (self.f(self.data[k], lx) > self.f(line, lx))
            gm = (self.f(self.data[k], mx) > self.f(line, mx))
            gr = (self.f(self.data[k], rx) > self.f(line, rx))
            if gl and gr:
                self.data[k] = line
                return
            
            if not gl and not gr:
                return
            
            if gm:
                self.data[k], line = line, self.data[k]
                gl = not gl
                
            if gl:
                r = m
                k = 2*k
            else:
                l = m
                k = 2*k+1
    
    def query(self, x):
        k = self.comp[x] + self.N0
        s = self.inf
        while k > 0:
            if self.data[k]:
                s = min(s, self.f(self.data[k], x))
            k = k >> 1
        return s
            
    def addline(self, line):
        self._update(1, line)
    
    def addlineseg(self, l, r, line):
        #区間[l, r)にlineを追加,l, rはXの元
        
        L = l+self.N0
        R = r+self.N0
        while L < R:
            if R & 1:
                R -= 1
                self._update(R, line)
            if L & 1:
                self._update(L, line)
                L += 1
            L >>= 1
            R >>= 1

N = int(input())
A = list(map(int, input().split()))
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

mX = max(X+A)
T = Lichaotree(list(range(mX + 1)))
N0 = T.N0
dp = [0]*N
for i in range(N):
    T.addlineseg(0, X[i], (-1, X[i] + Y[i] + dp[i-1]))
    T.addlineseg(X[i], N0, (1, -X[i] + Y[i] + dp[i-1]))
    dp[i] = T.query(A[i])

print(dp[-1])
0