結果

問題 No.1512 作文
ユーザー kamomekamome
提出日時 2021-05-21 23:09:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 568 ms / 2,000 ms
コード長 1,541 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 108,744 KB
最終ジャッジ日時 2024-04-18 16:43:27
合計ジャッジ時間 6,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,864 KB
testcase_01 AC 32 ms
52,480 KB
testcase_02 AC 33 ms
52,480 KB
testcase_03 AC 34 ms
52,480 KB
testcase_04 AC 456 ms
93,788 KB
testcase_05 AC 415 ms
93,432 KB
testcase_06 AC 469 ms
93,000 KB
testcase_07 AC 486 ms
93,312 KB
testcase_08 AC 438 ms
94,476 KB
testcase_09 AC 75 ms
76,292 KB
testcase_10 AC 72 ms
77,096 KB
testcase_11 AC 66 ms
76,016 KB
testcase_12 AC 72 ms
78,212 KB
testcase_13 AC 70 ms
76,672 KB
testcase_14 AC 131 ms
77,624 KB
testcase_15 AC 130 ms
77,648 KB
testcase_16 AC 149 ms
77,568 KB
testcase_17 AC 132 ms
76,904 KB
testcase_18 AC 131 ms
77,244 KB
testcase_19 AC 127 ms
76,724 KB
testcase_20 AC 133 ms
77,288 KB
testcase_21 AC 39 ms
60,160 KB
testcase_22 AC 38 ms
59,136 KB
testcase_23 AC 43 ms
61,056 KB
testcase_24 AC 41 ms
61,440 KB
testcase_25 AC 42 ms
61,440 KB
testcase_26 AC 34 ms
52,096 KB
testcase_27 AC 36 ms
52,736 KB
testcase_28 AC 34 ms
52,352 KB
testcase_29 AC 37 ms
52,352 KB
testcase_30 AC 36 ms
52,352 KB
testcase_31 AC 39 ms
59,520 KB
testcase_32 AC 43 ms
60,416 KB
testcase_33 AC 38 ms
59,520 KB
testcase_34 AC 44 ms
62,848 KB
testcase_35 AC 57 ms
89,088 KB
testcase_36 AC 61 ms
88,832 KB
testcase_37 AC 56 ms
77,440 KB
testcase_38 AC 60 ms
76,032 KB
testcase_39 AC 70 ms
77,540 KB
testcase_40 AC 568 ms
108,744 KB
testcase_41 AC 316 ms
108,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


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()
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