結果

問題 No.1512 作文
ユーザー hir355hir355
提出日時 2021-05-21 21:33:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 90,348 KB
最終ジャッジ日時 2024-04-18 14:42:27
合計ジャッジ時間 4,589 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,136 KB
testcase_01 AC 37 ms
53,412 KB
testcase_02 AC 37 ms
52,748 KB
testcase_03 AC 39 ms
52,468 KB
testcase_04 AC 146 ms
77,896 KB
testcase_05 AC 144 ms
77,892 KB
testcase_06 AC 136 ms
77,720 KB
testcase_07 AC 145 ms
78,024 KB
testcase_08 AC 136 ms
77,852 KB
testcase_09 AC 73 ms
71,808 KB
testcase_10 AC 81 ms
71,404 KB
testcase_11 AC 72 ms
71,340 KB
testcase_12 AC 82 ms
72,644 KB
testcase_13 AC 80 ms
72,272 KB
testcase_14 AC 90 ms
76,184 KB
testcase_15 AC 90 ms
75,656 KB
testcase_16 AC 90 ms
75,716 KB
testcase_17 AC 93 ms
76,064 KB
testcase_18 AC 93 ms
75,764 KB
testcase_19 AC 93 ms
76,220 KB
testcase_20 AC 85 ms
76,376 KB
testcase_21 AC 41 ms
54,848 KB
testcase_22 AC 37 ms
53,624 KB
testcase_23 AC 42 ms
55,248 KB
testcase_24 AC 41 ms
54,924 KB
testcase_25 AC 42 ms
55,040 KB
testcase_26 AC 38 ms
51,948 KB
testcase_27 AC 37 ms
52,444 KB
testcase_28 AC 38 ms
52,008 KB
testcase_29 AC 36 ms
52,180 KB
testcase_30 AC 37 ms
52,232 KB
testcase_31 AC 37 ms
53,668 KB
testcase_32 AC 39 ms
53,500 KB
testcase_33 AC 37 ms
52,208 KB
testcase_34 AC 41 ms
57,048 KB
testcase_35 AC 72 ms
90,348 KB
testcase_36 AC 72 ms
89,432 KB
testcase_37 AC 46 ms
71,068 KB
testcase_38 AC 53 ms
70,528 KB
testcase_39 AC 52 ms
71,136 KB
testcase_40 AC 153 ms
76,400 KB
testcase_41 AC 159 ms
76,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
dp = [0] * 26
g = [[] for _ in range(26)]
k = [0] * 26
for i in range(n):
    s = input()
    if sorted(s) == list(s):
        if s[0] == s[-1]:
            k[ord(s[0]) - 97] += len(s)
        else:
            g[ord(s[0]) - 97].append((ord(s[-1]) - 97, len(s)))
for i in range(25):
    dp[i] += k[i]
    for j, c in g[i]:
        dp[j] = max(dp[j], dp[i] + c)
    dp[i + 1] = max(dp[i + 1], dp[i])
print(dp[-1] + k[-1])
0