結果

問題 No.1512 作文
ユーザー kamomekamome
提出日時 2021-05-21 23:08:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,562 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 82,232 KB
実行使用メモリ 108,860 KB
最終ジャッジ日時 2024-04-18 16:43:01
合計ジャッジ時間 6,324 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,952 KB
testcase_01 AC 34 ms
52,564 KB
testcase_02 AC 35 ms
53,620 KB
testcase_03 AC 38 ms
53,756 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 74 ms
75,952 KB
testcase_10 AC 72 ms
77,004 KB
testcase_11 AC 72 ms
75,696 KB
testcase_12 AC 75 ms
78,032 KB
testcase_13 AC 73 ms
76,216 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 45 ms
60,904 KB
testcase_22 AC 44 ms
59,228 KB
testcase_23 AC 47 ms
61,396 KB
testcase_24 AC 45 ms
61,284 KB
testcase_25 AC 47 ms
62,752 KB
testcase_26 AC 37 ms
52,200 KB
testcase_27 AC 36 ms
52,648 KB
testcase_28 AC 35 ms
53,496 KB
testcase_29 AC 35 ms
52,612 KB
testcase_30 AC 37 ms
53,016 KB
testcase_31 AC 44 ms
60,560 KB
testcase_32 AC 40 ms
59,812 KB
testcase_33 AC 40 ms
59,036 KB
testcase_34 AC 49 ms
62,572 KB
testcase_35 AC 63 ms
89,816 KB
testcase_36 AC 64 ms
89,448 KB
testcase_37 AC 54 ms
78,996 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 461 ms
108,860 KB
testcase_41 AC 325 ms
107,708 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(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