結果
問題 | No.1512 作文 |
ユーザー |
![]() |
提出日時 | 2025-04-15 22:20:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 871 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 120,152 KB |
最終ジャッジ日時 | 2025-04-15 22:21:56 |
合計ジャッジ時間 | 5,166 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 WA * 14 |
ソースコード
def is_good(s): for i in range(len(s) - 1): if s[i] > s[i + 1]: return False return True n = int(input()) good = [] for _ in range(n): s = input().strip() if is_good(s): first = s[0] last = s[-1] length = len(s) good.append((first, last, length)) # Sort the good strings by their starting character good.sort(key=lambda x: x[0]) dp = [0] * 26 max_dp = [0] * 26 for first_char, last_char, length in good: s_start = ord(first_char) - ord('a') s_end = ord(last_char) - ord('a') current_max_prev = max_dp[s_start] new_val = current_max_prev + length if new_val > dp[s_end]: dp[s_end] = new_val # Update max_dp array current_max = 0 for i in range(26): if dp[i] > current_max: current_max = dp[i] max_dp[i] = current_max print(max(dp))