結果

問題 No.1512 作文
ユーザー tobusakana
提出日時 2022-11-26 11:19:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 569 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 86,528 KB
最終ジャッジ日時 2024-10-02 14:54:17
合計ジャッジ時間 6,465 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 26 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = [input() for i in range(N)]

# dp[X] = アルファベットXまで進んだときの最大得点
# あらかじめソートしておく

S = sorted(S)
dp = [0] * 26

def char_to_num(x):
  return ord(x) - ord('a')

for i in range(N):
  ok = True
  for j in range(len(S[i]) - 1):
    if S[i][j] > S[i][j + 1]:
      ok = False
      break
  if not ok:
    continue
      
  start = char_to_num(S[i][0])
  end = char_to_num(S[i][-1])
  length = len(S[i])
  
  if dp[end] < dp[start] + length:
    dp[end] = dp[start] + length
  
print(max(dp))
  



0