結果

問題 No.1512 作文
コンテスト
ユーザー norioc
提出日時 2025-10-20 01:55:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,034 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,772 KB
実行使用メモリ 112,764 KB
最終ジャッジ日時 2025-10-20 01:55:51
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections.abc import Iterable


def accum_dp1(xs: Iterable, f, op, e: int, size: int, init: Iterable, *, is_reset=True):
    dp = [e] * size
    for i, v in init:
        dp[i] = v

    for x in xs:
        pp = [e] * size if is_reset else dp.copy()
        dp, pp = pp, dp
        for i in range(size):
            for p, v in f(i, pp[i], x):
                if not (0 <= p < size): continue
                dp[p] = op(dp[p], v)

    return dp


N = int(input())
SS = [input() for _ in range(N)]


def is_ascendant(s: str) -> bool:
    p = 0
    for c in map(ord, s):
        if p > c: return False
        p = c

    return True


def conv(s: str):
    a = ord(s[0]) - ord('a')
    b = ord(s[-1]) - ord('a')
    return a, b, len(s)


def f(i, v, x):
    a, b, n = x  # (先頭文字, 末尾文字, 長さ)
    if i <= a:
        return [(b, v+n)]

    return []


def op(a, b):
    return max(a, b)


ss = [conv(s) for s in SS if is_ascendant(s)]
dp = accum_dp1(ss, f, op, 0, 26, [], is_reset=False)
ans = max(dp)
print(ans)
0