結果
| 問題 |
No.1512 作文
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 15:47:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 894 bytes |
| コンパイル時間 | 391 ms |
| コンパイル使用メモリ | 81,964 KB |
| 実行使用メモリ | 104,244 KB |
| 最終ジャッジ日時 | 2025-04-16 15:48:11 |
| 合計ジャッジ時間 | 5,392 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 17 |
ソースコード
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))
lam6er