結果

問題 No.1676 Coin Trade (Single)
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-10 22:16:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,989 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 90,936 KB
最終ジャッジ日時 2023-09-02 18:14:06
合計ジャッジ時間 8,263 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
70,784 KB
testcase_01 AC 67 ms
70,992 KB
testcase_02 AC 71 ms
71,160 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 214 ms
83,720 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 66 ms
71,112 KB
testcase_14 WA -
testcase_15 AC 68 ms
71,192 KB
testcase_16 WA -
testcase_17 AC 70 ms
70,892 KB
testcase_18 AC 71 ms
70,820 KB
testcase_19 WA -
testcase_20 AC 72 ms
71,116 KB
testcase_21 AC 71 ms
71,260 KB
testcase_22 WA -
testcase_23 AC 70 ms
71,208 KB
testcase_24 AC 68 ms
71,000 KB
testcase_25 AC 69 ms
70,820 KB
testcase_26 AC 69 ms
71,192 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 69 ms
71,160 KB
testcase_30 AC 68 ms
70,920 KB
testcase_31 AC 69 ms
70,684 KB
testcase_32 AC 68 ms
71,100 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 291 ms
90,092 KB
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        lres = self.ide_ele
        rres = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                rres = self.segfunc(self.seg[r], rres)
            if l & 1:
                lres = self.segfunc(lres, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        res = self.segfunc(lres, rres)
        return res

    def __str__(self): # for debug
        arr = [self.query(i,i+1) for i in range(self.n)]
        return str(arr)

def segfunc(x, y):
    if x >= y:
        return x
    else:
        return y

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    n, k = map(int, input().split())
    A = [0]*n
    B = [0]*n
    for i in range(n):
        a, m = map(int, input().split())
        A[i] = a
        b = list(map(int, input().split()))
        b = [j-1 for j in b]
        B[i] = b

    ans = 0
    seg = SegTree([0]*n, 0, max)
    for i in range(n):
        temp = 0
        for b in B[i]:
            x = A[i]-A[b]+seg.query(0, b)
            temp = max(temp, x)
        seg.update(i, temp)
        ans = max(ans, temp)
    print(ans)

if __name__ == '__main__':
    main()
0