結果

問題 No.1512 作文
ユーザー rlangevinrlangevin
提出日時 2023-01-09 17:07:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 94,660 KB
最終ジャッジ日時 2023-08-22 19:17:24
合計ジャッジ時間 6,661 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,336 KB
testcase_01 AC 74 ms
71,460 KB
testcase_02 AC 75 ms
71,472 KB
testcase_03 AC 77 ms
71,528 KB
testcase_04 AC 147 ms
77,068 KB
testcase_05 AC 145 ms
77,176 KB
testcase_06 AC 147 ms
77,240 KB
testcase_07 AC 146 ms
77,244 KB
testcase_08 AC 147 ms
77,288 KB
testcase_09 AC 106 ms
77,356 KB
testcase_10 AC 108 ms
77,992 KB
testcase_11 AC 104 ms
77,212 KB
testcase_12 AC 107 ms
78,640 KB
testcase_13 AC 105 ms
77,284 KB
testcase_14 AC 112 ms
77,204 KB
testcase_15 AC 111 ms
77,156 KB
testcase_16 AC 111 ms
77,204 KB
testcase_17 AC 109 ms
77,340 KB
testcase_18 AC 111 ms
77,296 KB
testcase_19 AC 109 ms
77,148 KB
testcase_20 AC 109 ms
77,304 KB
testcase_21 AC 78 ms
75,732 KB
testcase_22 AC 81 ms
75,664 KB
testcase_23 AC 82 ms
75,732 KB
testcase_24 AC 84 ms
75,676 KB
testcase_25 AC 82 ms
75,812 KB
testcase_26 AC 75 ms
71,092 KB
testcase_27 AC 73 ms
71,344 KB
testcase_28 AC 74 ms
71,248 KB
testcase_29 AC 72 ms
71,428 KB
testcase_30 AC 74 ms
71,216 KB
testcase_31 AC 78 ms
75,660 KB
testcase_32 AC 81 ms
75,752 KB
testcase_33 AC 80 ms
75,680 KB
testcase_34 AC 80 ms
75,636 KB
testcase_35 AC 102 ms
94,496 KB
testcase_36 AC 100 ms
94,660 KB
testcase_37 AC 91 ms
86,320 KB
testcase_38 AC 90 ms
76,280 KB
testcase_39 AC 93 ms
76,828 KB
testcase_40 AC 160 ms
77,048 KB
testcase_41 AC 154 ms
76,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def alp_to_num(cha):
    num = ord(cha) - ord("a")
    return num

N = int(readline())
D = [[0] * 26 for i in range(26)]
for i in range(N):
    S = list(readline().rstrip())
    S = list(map(alp_to_num, S))
    if S != sorted(S):
        continue
    a, b = S[0], S[-1]
    if a == b:
        D[a][a] += len(S)
    else:
        D[a][b] = max(D[a][b], len(S))
        
for i in range(26):
    for j in range(i + 1, 26):
        D[i][j] += D[i][i]
        
dp = [0] * 26
for i in range(1, 26):
    dp[i] = D[0][i]
    
for i in range(1, 26):
    for j in range(i + 1, 26):
        dp[j] = max(dp[j], dp[i] + D[i][j])
dp[-1] += D[-1][-1]
print(max(dp))    
0