結果

問題 No.1512 作文
ユーザー gew1fw
提出日時 2025-06-12 18:49:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 801 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 130,576 KB
最終ジャッジ日時 2025-06-12 18:50:10
合計ジャッジ時間 5,338 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
strings = [input().strip() for _ in range(n)]

valid = []
for s in strings:
    if len(s) == 0:
        continue
    is_sorted = True
    prev = s[0]
    for c in s[1:]:
        if c < prev:
            is_sorted = False
            break
        prev = c
    if is_sorted:
        valid.append((s[0], s[-1], len(s)))

dp = [0] * 26
max_dp = [0] * 26

for s_start, s_end, len_s in valid:
    s_start_idx = ord(s_start) - ord('a')
    s_end_idx = ord(s_end) - ord('a')
    max_prev = max_dp[s_start_idx]
    new_length = max_prev + len_s
    if new_length > dp[s_end_idx]:
        dp[s_end_idx] = new_length
        # Update max_dp
        current_max = 0
        for i in range(26):
            current_max = max(current_max, dp[i])
            max_dp[i] = current_max

print(max(dp))
0