結果

問題 No.1512 作文
ユーザー 👑 Kazun
提出日時 2021-05-21 21:35:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 541 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,576 KB
実行使用メモリ 78,244 KB
最終ジャッジ日時 2024-10-10 08:08:20
合計ジャッジ時間 5,216 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 20 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_good(S):
    p=""
    for s in S:
        if p>s:
            return False
        p=s
    return True

from string import ascii_lowercase as X

N=int(input())
D={a:{b:0 for b  in X} for a in X}

for _ in range(N):
    S=input()
    if not is_good(S): continue

    if S[0]==S[-1]:
        D[S[0]][S[-1]]+=len(S)
    else:
        D[S[0]][S[-1]]=max(D[S[0]][S[-1]],len(S))

X_len=len(X)
DP=[0]*X_len
for i in range(X_len):
    a=X[i]
    for j in range(i):
        b=X[j]
        DP[i]=max(DP[i],DP[j]+D[b][a]+D[a][a])

print(max(DP))
0