結果
問題 |
No.1512 作文
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:15:27 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 786 bytes |
コンパイル時間 | 227 ms |
コンパイル使用メモリ | 82,092 KB |
実行使用メモリ | 120,456 KB |
最終ジャッジ日時 | 2025-06-12 14:15:50 |
合計ジャッジ時間 | 4,383 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 17 |
ソースコード
n = int(input()) valid = [] for _ in range(n): s = input().strip() if not s: continue is_good = True prev = s[0] for c in s[1:]: if c < prev: is_good = False break prev = c if is_good: f_char = s[0] l_char = s[-1] length = len(s) valid.append((f_char, l_char, length)) dp = [0] * 26 prefix_max = [0] * 26 for f_char, l_char, length in valid: f = ord(f_char) - ord('a') l = ord(l_char) - ord('a') current_max_prev = prefix_max[f] candidate = current_max_prev + length if candidate > dp[l]: dp[l] = candidate # Update prefix_max prefix_max[0] = dp[0] for i in range(1, 26): prefix_max[i] = max(prefix_max[i-1], dp[i]) print(max(dp))