結果

問題 No.1512 作文
ユーザー lam6er
提出日時 2025-04-15 22:17:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 894 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,528 KB
実行使用メモリ 103,600 KB
最終ジャッジ日時 2025-04-15 22:19:17
合計ジャッジ時間 4,794 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

def is_good(s):
    for i in range(1, len(s)):
        if s[i] < s[i-1]:
            return False
    return True

good = []
for _ in range(n):
    s = input().strip()
    if is_good(s):
        first = ord(s[0])
        last = ord(s[-1])
        good.append((first, last, len(s)))

# Initialize dp array
dp = [-float('inf')] * 123
dp[0] = 0  # Virtual character at ASCII 0

max_dp = [0] * 123

# Initialize max_dp
max_so_far = -float('inf')
for c in range(123):
    max_so_far = max(max_so_far, dp[c])
    max_dp[c] = max_so_far

for f, l, length in good:
    current_max = max_dp[f]
    candidate = current_max + length
    if candidate > dp[l]:
        dp[l] = candidate
    # Update max_dp after updating dp
    max_so_far = -float('inf')
    for c in range(123):
        max_so_far = max(max_so_far, dp[c])
        max_dp[c] = max_so_far

ans = max(dp)
print(max(ans, 0))
0