結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-10-20 01:58:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 600 ms / 2,000 ms |
| コード長 | 1,042 bytes |
| コンパイル時間 | 223 ms |
| コンパイル使用メモリ | 82,760 KB |
| 実行使用メモリ | 115,976 KB |
| 最終ジャッジ日時 | 2025-10-20 01:58:53 |
| 合計ジャッジ時間 | 7,043 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
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 = sorted([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)
norioc