結果

問題 No.1512 作文
ユーザー lllllll88938494
提出日時 2022-05-30 20:43:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 146,036 KB
最終ジャッジ日時 2024-09-21 00:54:35
合計ジャッジ時間 5,603 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())

s=[]
for i in range(n):
    x=input()
    now=x[0]
    for i in range(1,len(x)):
        if  ord(now) > ord(x[i]):
            break
        now=x[i]
    else:
        s.append(x)
s.sort()

dp=[[-1]*27 for i in range(len(s)+1)]
dp[0][0]=0

for i in range(len(s)):
    for j in range(27):
        if dp[i][j] == -1:
            continue
        dp[i+1][j] = max(dp[i][j],dp[i+1][j])
        
        t = ord(s[i][0])-96
        if t >= j:#当末尾と候補文字先頭を比べる
            t2 = ord(s[i][-1])-96#候補文字末尾の場所に移動する
            dp[i+1][t2] = max(dp[i+1][t2],dp[i][j]+len(s[i]))
            

print(max(dp[-1]))


0