結果

問題 No.2549 Paint Eggs
ユーザー AlgeotAlgeot
提出日時 2023-11-25 13:58:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 3,101 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 118,248 KB
最終ジャッジ日時 2023-11-25 13:58:46
合計ジャッジ時間 13,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
66,276 KB
testcase_01 AC 59 ms
70,500 KB
testcase_02 AC 49 ms
64,196 KB
testcase_03 AC 64 ms
72,720 KB
testcase_04 AC 64 ms
72,748 KB
testcase_05 AC 65 ms
72,456 KB
testcase_06 AC 75 ms
76,172 KB
testcase_07 AC 75 ms
75,816 KB
testcase_08 AC 54 ms
65,972 KB
testcase_09 AC 66 ms
73,220 KB
testcase_10 AC 266 ms
109,284 KB
testcase_11 AC 269 ms
118,248 KB
testcase_12 AC 271 ms
104,324 KB
testcase_13 AC 268 ms
105,236 KB
testcase_14 AC 202 ms
102,276 KB
testcase_15 AC 123 ms
77,044 KB
testcase_16 AC 262 ms
104,968 KB
testcase_17 AC 241 ms
103,168 KB
testcase_18 AC 201 ms
102,756 KB
testcase_19 AC 236 ms
101,848 KB
testcase_20 AC 355 ms
116,732 KB
testcase_21 AC 323 ms
116,500 KB
testcase_22 AC 349 ms
116,736 KB
testcase_23 AC 349 ms
116,504 KB
testcase_24 AC 391 ms
116,736 KB
testcase_25 AC 278 ms
116,748 KB
testcase_26 AC 272 ms
116,528 KB
testcase_27 AC 293 ms
116,732 KB
testcase_28 AC 365 ms
116,532 KB
testcase_29 AC 315 ms
116,500 KB
testcase_30 AC 354 ms
116,732 KB
testcase_31 AC 325 ms
116,736 KB
testcase_32 AC 332 ms
116,748 KB
testcase_33 AC 308 ms
116,728 KB
testcase_34 AC 287 ms
116,528 KB
testcase_35 AC 386 ms
116,748 KB
testcase_36 AC 366 ms
116,736 KB
testcase_37 AC 323 ms
116,728 KB
testcase_38 AC 322 ms
116,504 KB
testcase_39 AC 317 ms
116,732 KB
testcase_40 AC 366 ms
116,736 KB
testcase_41 AC 377 ms
116,500 KB
testcase_42 AC 366 ms
116,496 KB
testcase_43 AC 357 ms
116,504 KB
testcase_44 AC 351 ms
116,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:

    @classmethod
    def X_op(cls, x, y):
        return min(x, y)

    def __init__(self, A):
        self.X_e = inf
        self.N = len(A)
        self.log = (self.N - 1).bit_length()
        self.size = 1 << self.log
        self.X = [self.X_e] * (self.size << 1)
        for i, x in enumerate(A):
            self.X[i + self.size] = x
        for i in range(self.size - 1, 0, -1):
            self.X[i] = self.X_op(self.X[i << 1], self.X[i << 1 | 1])

    def __iter__(self):
        for i in range(self.N):
            yield self.X[i + self.size]

    def __getitem__(self, i):
        i %= self.N
        return self.X[i + self.size]

    def __setitem__(self, i, x):
        i %= self.N
        i += self.size
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_op(self.X[i << 1], self.X[i << 1 | 1])

    def prod(self, L, R):
        L += self.size
        R += self.size
        vL, vR = self.X_e, self.X_e
        while L < R:
            if L & 1:
                vL = self.X_op(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_op(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_op(vL, vR)

    "Binary search for ok = n and ng = N"
    "f(x=seg.prod(L, r))"
    "TODO: f(e) = True"
    def right_search(self, L, f):
        L += self.size
        sm = self.X_e
        while True:
            while not L & 1:
                L >>= 1
            if not f(self.X_op(sm, self.X[L])):
                while L < self.size:
                    L <<= 1
                    if f(self.X_op(sm, self.X[L])):
                        sm = self.X_op(sm, self.X[L])
                        L += 1
                return L - self.size
            sm = self.X_op(sm, self.X[L])
            L += 1
            if L & -L == L: break
        return self.N

    def left_search(self, R, f):
        if R == 0: return
        R += self.size
        sm = self.X_e
        while True:
            R -= 1
            while R > 1 and R & 1:
                R >>= 1
            if not f(self.X_op(self.X[R], sm)):
                while R < self.size:
                    R = (R << 1) + 1
                    if f(self.X_op(self.X[R], sm)):
                        sm = self.X_op(self.X[R], sm)
                        R -= 1
                return R + 1 - self.size
            sm = self.X_op(self.X[R], sm)
            if R & -R == R: break
        return 0

    def __repr__(self):
        return str(self.X[self.size: self.size + self.N])


inf = 10 ** 18
N, M, K = map(int, input().split())
C = list(map(int, input().split()))
A = list(map(int, input().split()))
seg = SegTree([K * a for a in A])
ans = inf
for i in range(N):
    if i == 0:
        for j in range(K):
            c = C[j] - 1
            seg[c] = seg[c] - A[c]
        ans = seg.prod(0, M)
        continue
    if i + K - 1 >= N:
        continue
    c = C[i - 1] - 1
    seg[c] = seg[c] + A[c]
    c = C[i + K - 1] - 1
    seg[c] = seg[c] - A[c]
    ans = min(ans, seg.prod(0, M))
print(ans)
0