結果

問題 No.1512 作文
ユーザー kamomekamome
提出日時 2021-05-21 21:46:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,582 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 115,300 KB
最終ジャッジ日時 2024-04-18 15:02:13
合計ジャッジ時間 10,767 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 39 ms
52,480 KB
testcase_02 WA -
testcase_03 AC 36 ms
52,352 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 72 ms
76,032 KB
testcase_10 AC 73 ms
77,568 KB
testcase_11 AC 69 ms
75,948 KB
testcase_12 AC 74 ms
77,824 KB
testcase_13 AC 71 ms
76,744 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 42 ms
60,160 KB
testcase_22 AC 41 ms
59,136 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 46 ms
61,184 KB
testcase_26 AC 37 ms
52,224 KB
testcase_27 AC 36 ms
52,736 KB
testcase_28 AC 38 ms
52,672 KB
testcase_29 AC 36 ms
52,480 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 64 ms
89,088 KB
testcase_36 AC 63 ms
88,832 KB
testcase_37 AC 54 ms
76,928 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 RE -
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def segfunc(x, y):
    return max(x, y)


ide_ele = 0


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

    def update(self, k, x):
        k += self.num
        self.tree[k] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

    def get(self, k):
        return self.query(k, k+1)


N = int(input())
S = []
for i in range(N):
    s = list(map(lambda x: ord(x)-ord("a"), list(input())))
    t = sorted(s)
    if all(s[j] == t[j] for j in range(len(s))):
        S.append(s)
S.sort(key=lambda x: x[-1])
dp = SegTree([0]*26, segfunc, 0)

for i in range(len(S)):
    s = S[i][0]
    t = S[i][-1]
    n = len(S[i])
    dp.update(t, max(dp.query(0, s+1)+n, dp.get(t)))

print(dp.query(0, 27))
0